1
+ //! AA
1
2
#![ doc = include_str ! ( "./README.md" ) ]
2
- #![ doc = document_features:: document_features!( ) ]
3
+ //! BB
4
+ // #![doc = document_features::document_features!()]
5
+ //! CC
3
6
use alloc:: { slice, vec} ;
4
7
use core:: borrow:: Borrow ;
5
8
use core:: cmp:: min;
@@ -72,7 +75,6 @@ pub enum Action<T> {
72
75
/// use std::mem::{discriminant, Discriminant};
73
76
///
74
77
/// use bevy_text::undo_2::{Commands, IndepStateKey, SetOrTransition, SetTransAction};
75
- /// use bevy_text::undo_2::SetTransAction::Transition;
76
78
///
77
79
/// #[derive(Copy, Clone, Debug)]
78
80
/// struct State {
@@ -137,24 +139,23 @@ pub enum Action<T> {
137
139
/// B,
138
140
/// }
139
141
///
140
- /// use bevy_text::undo_2::SetTransAction::*;
141
142
/// let mut commands = Commands::new();
142
143
/// let mut state = State::new();
143
144
///
144
145
/// let c = SetCommands::Color(1.);
145
146
/// state.apply_set(&c);
146
- /// commands.push(Set(c));
147
+ /// commands.push(SetOrTransition:: Set(c));
147
148
///
148
- /// commands.push(Transition(TransitionCommand::A));
149
- /// commands.push(Transition(TransitionCommand::B));
149
+ /// commands.push(SetOrTransition:: Transition(TransitionCommand::A));
150
+ /// commands.push(SetOrTransition:: Transition(TransitionCommand::B));
150
151
///
151
152
/// let c = SetCommands::Length(10.);
152
153
/// state.apply_set(&c);
153
- /// commands.push(Set(c));
154
+ /// commands.push(SetOrTransition:: Set(c));
154
155
///
155
156
/// let c = SetCommands::Color(2.);
156
157
/// state.apply_set(&c);
157
- /// commands.push(Set(c));
158
+ /// commands.push(SetOrTransition:: Set(c));
158
159
///
159
160
/// commands.apply_undo(|c| {
160
161
/// assert_eq!(c, SetTransAction::Set(&SetCommands::Color(1.)));
@@ -196,7 +197,9 @@ pub enum SetOrTransition<S, T> {
196
197
/// }
197
198
/// ```
198
199
pub trait IndepStateKey {
200
+ /// KeyType
199
201
type KeyType : PartialEq + Hash ;
202
+ /// key
200
203
fn key ( & self ) -> Self :: KeyType ;
201
204
}
202
205
@@ -217,22 +220,22 @@ pub enum SetTransAction<'a, S: IndepStateKey, T> {
217
220
}
218
221
219
222
impl < T > Action < T > {
223
+ /// as_inner
220
224
pub fn as_inner ( & self ) -> & T {
221
225
match self {
222
- Action :: Do ( a) => a,
223
- Action :: Undo ( a) => a,
226
+ Action :: Do ( a) | Action :: Undo ( a) => a,
224
227
}
225
228
}
229
+ /// as_inner_mut
226
230
pub fn as_inner_mut ( & mut self ) -> & mut T {
227
231
match self {
228
- Action :: Do ( a) => a,
229
- Action :: Undo ( a) => a,
232
+ Action :: Do ( a) | Action :: Undo ( a) => a,
230
233
}
231
234
}
235
+ /// into_inner
232
236
pub fn into_inner ( self ) -> T {
233
237
match self {
234
- Action :: Do ( a) => a,
235
- Action :: Undo ( a) => a,
238
+ Action :: Do ( a) | Action :: Undo ( a) => a,
236
239
}
237
240
}
238
241
}
@@ -271,11 +274,11 @@ impl<T> Action<T> {
271
274
#[ derive( Copy , Clone , Debug , Eq , PartialEq , Hash ) ]
272
275
#[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
273
276
pub enum CommandItem < T > {
274
- // A command typically created by [Commands::push](Commands#method.push)
277
+ /// A command typically created by [Commands::push](Commands#method.push)
275
278
Command ( T ) ,
276
- // Signify that `count` CommandItem previous to this item are undone.
277
- //
278
- // Where `count` refers to this variant field.
279
+ /// Signify that `count` CommandItem previous to this item are undone.
280
+ ///
281
+ /// Where `count` refers to this variant field.
279
282
Undo ( usize ) ,
280
283
}
281
284
@@ -379,8 +382,11 @@ struct IndexedAction {
379
382
/// the `command` is `Some(c)` the slice will be replace by `c`.
380
383
#[ derive( Debug ) ]
381
384
pub struct Merge < ' a , T > {
385
+ /// start
382
386
pub start : IterRealized < ' a , T > ,
387
+ /// end
383
388
pub end : IterRealized < ' a , T > ,
389
+ /// command
384
390
pub command : Option < T > ,
385
391
}
386
392
@@ -394,8 +400,11 @@ pub struct Merge<'a, T> {
394
400
/// commands denoted by `commands`.
395
401
#[ derive( Debug ) ]
396
402
pub struct Splice < ' a , T , I : IntoIterator < Item = T > > {
403
+ /// start
397
404
pub start : IterRealized < ' a , T > ,
405
+ /// end
398
406
pub end : IterRealized < ' a , T > ,
407
+ /// commands
399
408
pub commands : I ,
400
409
}
401
410
@@ -798,9 +807,7 @@ impl<T> Commands<T> {
798
807
/// ```
799
808
#[ must_use = "the returned actions should be realized" ]
800
809
pub fn undo_repeat ( & mut self , repeat : usize ) -> ActionIter < ' _ , T > {
801
- let repeat = if let Some ( v) = repeat. checked_sub ( 1 ) {
802
- v
803
- } else {
810
+ let Some ( repeat) = repeat. checked_sub ( 1 ) else {
804
811
return ActionIter :: new ( ) ;
805
812
} ;
806
813
let l = self . len ( ) ;
@@ -878,6 +885,7 @@ impl<T> Commands<T> {
878
885
} ;
879
886
self . undo_repeat ( to_undo)
880
887
}
888
+ /// rebuild
881
889
#[ must_use = "the returned command should be undone" ]
882
890
pub fn rebuild ( & mut self ) -> ActionIter < ' _ , T > {
883
891
if !self . is_undoing ( ) {
@@ -963,9 +971,7 @@ impl<T> Commands<T> {
963
971
/// ```
964
972
#[ must_use = "the returned actions should be realized" ]
965
973
pub fn redo_repeat ( & mut self , repeat : usize ) -> ActionIter < ' _ , T > {
966
- let repeat = if let Some ( v) = repeat. checked_sub ( 1 ) {
967
- v
968
- } else {
974
+ let Some ( repeat) = repeat. checked_sub ( 1 ) else {
969
975
return ActionIter :: new ( ) ;
970
976
} ;
971
977
let l = self . len ( ) ;
@@ -1908,13 +1914,13 @@ impl<'a, T> From<Merge<'a, T>> for Splice<'a, T, option::IntoIter<T>> {
1908
1914
}
1909
1915
1910
1916
impl < T > IterRealized < ' _ , T > {
1911
- // Returned the index of the command refered by the previous non `None` result of call to
1912
- // `next`.
1913
- //
1914
- // This same command is accessible by indexing [Commands] at this returned index.
1915
- //
1916
- // This index can be used to set the first realized command with
1917
- // [Commands::undo_or_redo_to_index](Commands#method.undo_or_redo_to_index).
1917
+ /// Returned the index of the command refered by the previous non `None` result of call to
1918
+ /// `next`.
1919
+ ///
1920
+ /// This same command is accessible by indexing [Commands] at this returned index.
1921
+ ///
1922
+ /// This index can be used to set the first realized command with
1923
+ /// [Commands::undo_or_redo_to_index](Commands#method.undo_or_redo_to_index).
1918
1924
pub fn index ( & self ) -> usize {
1919
1925
self . current
1920
1926
}
0 commit comments