@@ -6,17 +6,17 @@ use core::iter::FusedIterator;
6
6
use core:: ops:: ControlFlow ;
7
7
use core:: ops:: { Deref , Index } ;
8
8
use core:: option;
9
- use std :: fmt:: Debug ;
9
+ use core :: fmt:: Debug ;
10
10
use std:: hash:: { DefaultHasher , Hash , Hasher as _} ;
11
- use std :: slice:: SliceIndex ;
12
- use std :: { slice, vec} ;
11
+ use core :: slice:: SliceIndex ;
12
+ use alloc :: { slice, vec} ;
13
13
14
14
#[ cfg( feature = "serde" ) ]
15
15
use serde:: { Deserialize , Serialize } ;
16
16
17
17
/// Action that should be taken on the paired command
18
18
///
19
- /// [ActionIter] item type is a pair `(Action, C)` where
19
+ /// [` ActionIter` ] item type is a pair `(Action, C)` where
20
20
/// C is the client defined command type. `(Action::Do, t)`
21
21
/// signifies that the command `t` shall be executed. `(Action::Undo,t)`
22
22
/// means it shall be undone.
@@ -50,24 +50,24 @@ pub enum Action<T> {
50
50
/// transition are interlieved with other transitions.
51
51
///
52
52
/// So the set of all commands can be partitionned in two: the set of transitions affecting
53
- /// indepent state, and the other transitions. [SetOrTransition] provides such a partition.
53
+ /// indepent state, and the other transitions. [` SetOrTransition` ] provides such a partition.
54
54
/// It is supposed to be used as the element of the [Commands]:
55
55
/// `Commands<SetOrTransition::<MyStateCommands,MyTransitions>`.
56
56
///
57
- /// [Commands] provides dedicateds methods (see [apply_actions][Commands::apply_actions]) to simplify the use of
57
+ /// [Commands] provides dedicateds methods (see [` apply_actions` ][Commands::apply_actions]) to simplify the use of
58
58
/// commands partitionned in independent state and transitions.
59
59
///
60
60
/// State commands are supposed to represent the setting of an indepent state such as "set the view
61
61
/// port to `x`, `y`, `lx`, `ly`". When a independent state command is undone within the `apply_actions`, the
62
- /// algorithm will look for the previous application of a command the same key [IndepStateKey::key] and will
62
+ /// algorithm will look for the previous application of a command the same key [` IndepStateKey::key` ] and will
63
63
/// command the application of it.
64
64
///
65
65
/// # Example
66
66
///
67
67
/// In this example we use commands that set the state `color` and `length`.
68
68
///
69
69
/// In the commands registered the previous states of `color` and `length` are not stored
70
- /// but [Commands::apply_actions] will retrieve automatically the value to set for this states.
70
+ /// but [` Commands::apply_actions` ] will retrieve automatically the value to set for this states.
71
71
/// ```
72
72
/// use std::mem::{discriminant, Discriminant};
73
73
///
@@ -200,7 +200,7 @@ pub trait IndepStateKey {
200
200
}
201
201
202
202
/// The actions asked to be performed by the user
203
- /// when calling [Commands::apply_actions]
203
+ /// when calling [` Commands::apply_actions` ]
204
204
#[ derive( Debug , Copy , Clone , PartialEq , Eq , Hash ) ]
205
205
pub enum SetTransAction < ' a , S : IndepStateKey , T > {
206
206
/// Ask the execution of the transition .0
@@ -320,7 +320,7 @@ pub enum CommandItem<T> {
320
320
///
321
321
/// # Representation
322
322
///
323
- /// `Commands` owns a slice of [CommandItem] that is accesible
323
+ /// `Commands` owns a slice of [` CommandItem` ] that is accesible
324
324
/// by dereferencing the command.
325
325
#[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
326
326
#[ derive( Eq ) ]
@@ -330,7 +330,7 @@ pub struct Commands<T> {
330
330
undo_cache : Vec < IndexedAction > ,
331
331
}
332
332
impl < T : Debug > Debug for Commands < T > {
333
- fn fmt ( & self , f : & mut std :: fmt:: Formatter < ' _ > ) -> std :: fmt:: Result {
333
+ fn fmt ( & self , f : & mut core :: fmt:: Formatter < ' _ > ) -> core :: fmt:: Result {
334
334
f. debug_struct ( "Commands" )
335
335
. field ( "commands" , & self . commands )
336
336
. finish ( )
@@ -342,7 +342,7 @@ impl<T: PartialEq> PartialEq for Commands<T> {
342
342
}
343
343
}
344
344
impl < T : Hash > Hash for Commands < T > {
345
- fn hash < H : std :: hash:: Hasher > ( & self , state : & mut H ) {
345
+ fn hash < H : core :: hash:: Hasher > ( & self , state : & mut H ) {
346
346
self . commands . hash ( state) ;
347
347
}
348
348
}
@@ -368,11 +368,11 @@ struct IndexedAction {
368
368
index : usize ,
369
369
}
370
370
371
- /// Specify a merge when calling [Commands::merge](Commands#method.merge)
371
+ /// Specify a merge when calling [` Commands::merge` ](Commands#method.merge)
372
372
///
373
373
/// The [`end`, `start`) bounds the slice of command that will
374
374
/// be removed during the merge. `end` and `start` are in reverse order
375
- /// because [IterRealized] goes backward.
375
+ /// because [` IterRealized` ] goes backward.
376
376
///
377
377
/// If `command` is `None` then the slice will be removed, otherwise if
378
378
/// the `command` is `Some(c)` the slice will be replace by `c`.
@@ -383,11 +383,11 @@ pub struct Merge<'a, T> {
383
383
pub command : Option < T > ,
384
384
}
385
385
386
- /// Specify a splice when calling [Commands::splice](Commands#method.splice)
386
+ /// Specify a splice when calling [` Commands::splice` ](Commands#method.splice)
387
387
///
388
388
/// The [`end`, `start`) bounds the slice of command that will
389
389
/// be removed during the merge. `end` and `start` are in reverse order
390
- /// because [IterRealized] goes backward.
390
+ /// because [` IterRealized` ] goes backward.
391
391
///
392
392
/// The removed slice is then replaced by the sequence (not reversed) of
393
393
/// commands denoted by `commands`.
@@ -399,8 +399,8 @@ pub struct Splice<'a, T, I: IntoIterator<Item = T>> {
399
399
}
400
400
401
401
#[ derive( Debug ) ]
402
- /// Iterator of actions returned by [Commands::undo](Commands#method.undo) and
403
- /// [Commands::redo](Commands#method.redo)
402
+ /// Iterator of actions returned by [` Commands::undo` ](Commands#method.undo) and
403
+ /// [` Commands::redo` ](Commands#method.redo)
404
404
pub struct ActionIter < ' a , T > {
405
405
commands : & ' a [ CommandItem < T > ] ,
406
406
to_do : slice:: Iter < ' a , IndexedAction > ,
@@ -415,7 +415,7 @@ impl<T> Clone for ActionIter<'_, T> {
415
415
}
416
416
417
417
#[ derive( Debug ) ]
418
- /// The type of the iterator returned by [Commands::iter_realized](Commands#method.iter_realized).
418
+ /// The type of the iterator returned by [` Commands::iter_realized` ](Commands#method.iter_realized).
419
419
pub struct IterRealized < ' a , T > {
420
420
commands : & ' a [ CommandItem < T > ] ,
421
421
current : usize ,
@@ -427,17 +427,17 @@ impl<T> Clone for IterRealized<'_, T> {
427
427
}
428
428
429
429
impl < S : IndepStateKey , T > Commands < SetOrTransition < S , T > > {
430
- /// Apply a series of actions represented by the type [SetTransAction] executed
430
+ /// Apply a series of actions represented by the type [` SetTransAction` ] executed
431
431
/// by argument `f`.
432
432
///
433
433
/// The list of action to be applied are provided by the call of `act` on
434
434
/// this [Commands]. This may be defined, for exemple as, `|c| c.redo()`
435
435
///
436
- /// This command only exist when the commands have the type [SetOrTransition].
436
+ /// This command only exist when the commands have the type [` SetOrTransition` ].
437
437
/// See the documentation of this type for an explanation.
438
438
///
439
439
/// The function `f` will be called with [Do][SetTransAction::Do] and [Undo][SetTransAction::Undo] of commands that are
440
- /// represented as [transitions][SetOrTransition::Transition], and [Set][SetTransAction::Set] or [SetToInitial][SetTransAction::SetToInitial]
440
+ /// represented as [transitions][SetOrTransition::Transition], and [Set][SetTransAction::Set] or [` SetToInitial` ][SetTransAction::SetToInitial]
441
441
/// (most probably only once) per [key][IndepStateKey::key] for commands that represent independent state setting.
442
442
pub fn apply_actions (
443
443
& mut self ,
@@ -446,17 +446,17 @@ impl<S: IndepStateKey, T> Commands<SetOrTransition<S, T>> {
446
446
) {
447
447
let mut state_commands = Vec :: new ( ) ;
448
448
for command in act ( self ) {
449
- Self :: apply_action ( command, & mut state_commands, & mut f)
449
+ Self :: apply_action ( command, & mut state_commands, & mut f) ;
450
450
}
451
451
self . restore_state ( state_commands, f) ;
452
452
}
453
453
/// Equivalent to `apply_actions(|c| c.undo(),f)`.
454
454
pub fn apply_undo ( & mut self , f : impl FnMut ( SetTransAction < S , T > ) ) {
455
- self . apply_actions ( |s| s . undo ( ) , f)
455
+ self . apply_actions ( Commands :: undo, f) ;
456
456
}
457
457
/// Equivalent to `apply_actions(|c| c.redo(),f)`.
458
458
pub fn apply_redo ( & mut self , f : impl FnMut ( SetTransAction < S , T > ) ) {
459
- self . apply_actions ( |s| s . redo ( ) , f)
459
+ self . apply_actions ( Commands :: redo, f) ;
460
460
}
461
461
fn apply_action (
462
462
action : Action < & SetOrTransition < S , T > > ,
@@ -467,7 +467,7 @@ impl<S: IndepStateKey, T> Commands<SetOrTransition<S, T>> {
467
467
Action :: Do ( SetOrTransition :: Transition ( tr) ) => f ( SetTransAction :: Do ( tr) ) ,
468
468
Action :: Undo ( SetOrTransition :: Transition ( tr) ) => f ( SetTransAction :: Undo ( tr) ) ,
469
469
Action :: Do ( SetOrTransition :: Set ( s) ) | Action :: Undo ( SetOrTransition :: Set ( s) ) => {
470
- state_keys. push ( Some ( s. key ( ) ) )
470
+ state_keys. push ( Some ( s. key ( ) ) ) ;
471
471
}
472
472
}
473
473
}
@@ -511,7 +511,7 @@ impl<S: IndepStateKey, T> Commands<SetOrTransition<S, T>> {
511
511
}
512
512
if l > 0 {
513
513
for disc in state_keys. into_iter ( ) . flatten ( ) {
514
- f ( SetTransAction :: SetToInitial ( disc) )
514
+ f ( SetTransAction :: SetToInitial ( disc) ) ;
515
515
}
516
516
}
517
517
}
@@ -531,7 +531,7 @@ impl<T> Commands<T> {
531
531
}
532
532
/// Reserve space for new commands
533
533
pub fn reserve ( & mut self , additional : usize ) {
534
- self . commands . reserve ( additional)
534
+ self . commands . reserve ( additional) ;
535
535
}
536
536
537
537
/// Return a reference to the last command
@@ -691,7 +691,7 @@ impl<T> Commands<T> {
691
691
producer : impl FnOnce ( ) -> T ,
692
692
) {
693
693
if !self . update_last ( updater) {
694
- self . push ( producer ( ) )
694
+ self . push ( producer ( ) ) ;
695
695
}
696
696
}
697
697
@@ -1181,7 +1181,7 @@ impl<T> Commands<T> {
1181
1181
}
1182
1182
1183
1183
/// Repeat undo or redo so that the last realiazed command correspond to
1184
- /// the [CommandItem] index passed `index`.
1184
+ /// the [` CommandItem` ] index passed `index`.
1185
1185
///
1186
1186
/// ```
1187
1187
/// use crate::undo_2::{Action,Commands, CommandItem};
@@ -1337,7 +1337,7 @@ impl<T> Commands<T> {
1337
1337
CommandItem :: Undo ( _) => false ,
1338
1338
CommandItem :: Command ( c) => stop_pred ( c) ,
1339
1339
} ) {
1340
- self . remove_first ( i)
1340
+ self . remove_first ( i) ;
1341
1341
}
1342
1342
}
1343
1343
/// Try to keep `count` most recent commands by dropping removable commands.
@@ -1404,7 +1404,7 @@ impl<T> Commands<T> {
1404
1404
/// ```
1405
1405
pub fn keep_last ( & mut self , count : usize ) {
1406
1406
let i = self . len ( ) . saturating_sub ( count) ;
1407
- self . remove_first ( i)
1407
+ self . remove_first ( i) ;
1408
1408
}
1409
1409
/// Remove `count` or less of the oldest command.
1410
1410
///
@@ -1479,11 +1479,10 @@ impl<T> Commands<T> {
1479
1479
fn remove_i ( & self , mut i : usize , end : usize ) -> usize {
1480
1480
let i0 = i;
1481
1481
for j in i0..end {
1482
- if let CommandItem :: Undo ( count) = self . commands [ j] {
1483
- if j - count - 1 < i {
1484
- i = self . remove_i ( j - count - 1 , i)
1482
+ if let CommandItem :: Undo ( count) = self . commands [ j]
1483
+ && j - count - 1 < i {
1484
+ i = self . remove_i ( j - count - 1 , i) ;
1485
1485
}
1486
- }
1487
1486
}
1488
1487
i
1489
1488
}
@@ -1538,7 +1537,7 @@ impl<T> Commands<T> {
1538
1537
/// Merge a sequence of [*realized commands*](Commands#method.iter_realized) into a single new
1539
1538
/// command or remove the sequence.
1540
1539
///
1541
- /// The parameter `f` takes as an input a [IterRealized], and returns a
1540
+ /// The parameter `f` takes as an input a [` IterRealized` ], and returns a
1542
1541
/// [`std::ops::ControlFlow<Option<Merge>, Option<Merge>>`](std::ops::ControlFlow). If the
1543
1542
/// returned value contain a `Some(merge)`[Merge], the action specified by `merge` is then
1544
1543
/// inserted in place.
@@ -1598,15 +1597,15 @@ impl<T> Commands<T> {
1598
1597
{
1599
1598
use ControlFlow :: * ;
1600
1599
self . splice ( |it| match f ( it) {
1601
- Continue ( c) => Continue ( c. map ( |m| m . into ( ) ) ) ,
1602
- Break ( c) => Break ( c. map ( |m| m . into ( ) ) ) ,
1603
- } )
1600
+ Continue ( c) => Continue ( c. map ( Into :: into) ) ,
1601
+ Break ( c) => Break ( c. map ( Into :: into) ) ,
1602
+ } ) ;
1604
1603
}
1605
1604
1606
1605
/// Replace a sequence of command by an other. This is a generalization of
1607
- /// [Commands::merge](Commands#method.merge)
1606
+ /// [` Commands::merge` ](Commands#method.merge)
1608
1607
///
1609
- /// The parameter `f` takes as an input a [IterRealized], and returns a
1608
+ /// The parameter `f` takes as an input a [` IterRealized` ], and returns a
1610
1609
/// [`std::ops::ControlFlow<Option<Splice>, Option<Splice>>`](std::ops::ControlFlow). If the returned value
1611
1610
/// contain a `Some(splice)`[Splice], the actions specified by `splice` are then inserted in
1612
1611
/// place.
@@ -1705,7 +1704,7 @@ impl<T> Commands<T> {
1705
1704
let end_i = rev_start;
1706
1705
let start_i = rev_end;
1707
1706
self . commands
1708
- . splice ( start_i..end_i, commands. into_iter ( ) . map ( |c| c . into ( ) ) ) ;
1707
+ . splice ( start_i..end_i, commands. into_iter ( ) . map ( Into :: into) ) ;
1709
1708
}
1710
1709
1711
1710
/// Clean up the history of all the undone commands.
@@ -1736,7 +1735,7 @@ impl<T> Commands<T> {
1736
1735
/// assert_eq!(*c, [A.into(), C.into()]);
1737
1736
/// ```
1738
1737
pub fn remove_all_undone ( & mut self ) {
1739
- self . remove_undone ( |i| i)
1738
+ self . remove_undone ( |i| i) ;
1740
1739
}
1741
1740
/// Clean up the history of all undone commands before a given
1742
1741
/// [realized iterator](Commands#method.iter_realized).
@@ -1833,7 +1832,7 @@ impl<T: Clone> Clone for Commands<T> {
1833
1832
}
1834
1833
}
1835
1834
fn clone_from ( & mut self , source : & Self ) {
1836
- self . commands . clone_from ( & source. commands )
1835
+ self . commands . clone_from ( & source. commands ) ;
1837
1836
}
1838
1837
}
1839
1838
@@ -1855,13 +1854,13 @@ impl<T> Borrow<[CommandItem<T>]> for Commands<T> {
1855
1854
}
1856
1855
impl < T > Extend < T > for Commands < T > {
1857
1856
fn extend < I : IntoIterator < Item = T > > ( & mut self , iter : I ) {
1858
- self . commands . extend ( iter. into_iter ( ) . map ( |c| c . into ( ) ) )
1857
+ self . commands . extend ( iter. into_iter ( ) . map ( Into :: into) ) ;
1859
1858
}
1860
1859
}
1861
1860
impl < T > FromIterator < T > for Commands < T > {
1862
1861
fn from_iter < I : IntoIterator < Item = T > > ( iter : I ) -> Self {
1863
1862
Self {
1864
- commands : iter. into_iter ( ) . map ( |c| c . into ( ) ) . collect ( ) ,
1863
+ commands : iter. into_iter ( ) . map ( Into :: into) . collect ( ) ,
1865
1864
undo_cache : vec ! [ ] ,
1866
1865
}
1867
1866
}
@@ -2066,14 +2065,14 @@ fn do_simplify(to_do: &mut [IndexedAction]) {
2066
2065
if to_do[ cursor] . is_reverse_of ( action) {
2067
2066
cursor += 1 ;
2068
2067
while cursor < l && to_do[ cursor] . action == Skip {
2069
- cursor += 1
2068
+ cursor += 1 ;
2070
2069
}
2071
2070
} else {
2072
2071
to_do[ analyzed + 1 ..cursor]
2073
2072
. iter_mut ( )
2074
2073
. for_each ( |a| a. action = Skip ) ;
2075
2074
if cursor == analyzed + 1 {
2076
- cursor = analyzed
2075
+ cursor = analyzed;
2077
2076
} else {
2078
2077
cursor = analyzed + 1 ;
2079
2078
analyzed += 1 ;
0 commit comments