Skip to content

Commit 7c35a3b

Browse files
committed
More doc work
1 parent 7d31a8b commit 7c35a3b

File tree

4 files changed

+42
-35
lines changed

4 files changed

+42
-35
lines changed

crates/bevy_text/src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ mod pipeline;
4242
mod text;
4343
mod text2d;
4444
mod text_access;
45-
mod undo_2;
45+
pub mod undo_2;
4646

4747
use bevy_camera::{visibility::VisibilitySystems, CameraUpdateSystems};
4848
pub use bounds::*;
@@ -56,7 +56,6 @@ pub use pipeline::*;
5656
pub use text::*;
5757
pub use text2d::*;
5858
pub use text_access::*;
59-
pub use undo_2::*;
6059

6160
/// The text prelude.
6261
///

crates/bevy_text/src/undo_2/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Undo done the right way
22

3-
Via [](https://gitlab.com/okannen/undo_2/-/tree/b32c34edb2c15c266b946f0d82188624f3aa3fdc)
3+
Via [original](https://gitlab.com/okannen/undo_2/-/tree/b32c34edb2c15c266b946f0d82188624f3aa3fdc)
44

55
## Introduction
66

@@ -56,7 +56,7 @@ and it is similar to vim :earlier.
5656

5757
Add the dependency to the cargo file:
5858

59-
```[toml]
59+
```toml
6060
[dependencies]
6161
undo_2 = "0.1"
6262
```

crates/bevy_text/src/undo_2/lib.rs

Lines changed: 37 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1+
//! AA
12
#![doc = include_str!("./README.md")]
2-
#![doc = document_features::document_features!()]
3+
//! BB
4+
// #![doc = document_features::document_features!()]
5+
//! CC
36
use alloc::{slice, vec};
47
use core::borrow::Borrow;
58
use core::cmp::min;
@@ -72,7 +75,6 @@ pub enum Action<T> {
7275
/// use std::mem::{discriminant, Discriminant};
7376
///
7477
/// use bevy_text::undo_2::{Commands, IndepStateKey, SetOrTransition, SetTransAction};
75-
/// use bevy_text::undo_2::SetTransAction::Transition;
7678
///
7779
/// #[derive(Copy, Clone, Debug)]
7880
/// struct State {
@@ -137,24 +139,23 @@ pub enum Action<T> {
137139
/// B,
138140
/// }
139141
///
140-
/// use bevy_text::undo_2::SetTransAction::*;
141142
/// let mut commands = Commands::new();
142143
/// let mut state = State::new();
143144
///
144145
/// let c = SetCommands::Color(1.);
145146
/// state.apply_set(&c);
146-
/// commands.push(Set(c));
147+
/// commands.push(SetOrTransition::Set(c));
147148
///
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));
150151
///
151152
/// let c = SetCommands::Length(10.);
152153
/// state.apply_set(&c);
153-
/// commands.push(Set(c));
154+
/// commands.push(SetOrTransition::Set(c));
154155
///
155156
/// let c = SetCommands::Color(2.);
156157
/// state.apply_set(&c);
157-
/// commands.push(Set(c));
158+
/// commands.push(SetOrTransition::Set(c));
158159
///
159160
/// commands.apply_undo(|c| {
160161
/// assert_eq!(c, SetTransAction::Set(&SetCommands::Color(1.)));
@@ -196,7 +197,9 @@ pub enum SetOrTransition<S, T> {
196197
/// }
197198
/// ```
198199
pub trait IndepStateKey {
200+
/// KeyType
199201
type KeyType: PartialEq + Hash;
202+
/// key
200203
fn key(&self) -> Self::KeyType;
201204
}
202205

@@ -217,22 +220,22 @@ pub enum SetTransAction<'a, S: IndepStateKey, T> {
217220
}
218221

219222
impl<T> Action<T> {
223+
/// as_inner
220224
pub fn as_inner(&self) -> &T {
221225
match self {
222-
Action::Do(a) => a,
223-
Action::Undo(a) => a,
226+
Action::Do(a) | Action::Undo(a) => a,
224227
}
225228
}
229+
/// as_inner_mut
226230
pub fn as_inner_mut(&mut self) -> &mut T {
227231
match self {
228-
Action::Do(a) => a,
229-
Action::Undo(a) => a,
232+
Action::Do(a) | Action::Undo(a) => a,
230233
}
231234
}
235+
/// into_inner
232236
pub fn into_inner(self) -> T {
233237
match self {
234-
Action::Do(a) => a,
235-
Action::Undo(a) => a,
238+
Action::Do(a) | Action::Undo(a) => a,
236239
}
237240
}
238241
}
@@ -271,11 +274,11 @@ impl<T> Action<T> {
271274
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
272275
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
273276
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)
275278
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.
279282
Undo(usize),
280283
}
281284

@@ -379,8 +382,11 @@ struct IndexedAction {
379382
/// the `command` is `Some(c)` the slice will be replace by `c`.
380383
#[derive(Debug)]
381384
pub struct Merge<'a, T> {
385+
/// start
382386
pub start: IterRealized<'a, T>,
387+
/// end
383388
pub end: IterRealized<'a, T>,
389+
/// command
384390
pub command: Option<T>,
385391
}
386392

@@ -394,8 +400,11 @@ pub struct Merge<'a, T> {
394400
/// commands denoted by `commands`.
395401
#[derive(Debug)]
396402
pub struct Splice<'a, T, I: IntoIterator<Item = T>> {
403+
/// start
397404
pub start: IterRealized<'a, T>,
405+
/// end
398406
pub end: IterRealized<'a, T>,
407+
/// commands
399408
pub commands: I,
400409
}
401410

@@ -798,9 +807,7 @@ impl<T> Commands<T> {
798807
/// ```
799808
#[must_use = "the returned actions should be realized"]
800809
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 {
804811
return ActionIter::new();
805812
};
806813
let l = self.len();
@@ -878,6 +885,7 @@ impl<T> Commands<T> {
878885
};
879886
self.undo_repeat(to_undo)
880887
}
888+
/// rebuild
881889
#[must_use = "the returned command should be undone"]
882890
pub fn rebuild(&mut self) -> ActionIter<'_, T> {
883891
if !self.is_undoing() {
@@ -963,9 +971,7 @@ impl<T> Commands<T> {
963971
/// ```
964972
#[must_use = "the returned actions should be realized"]
965973
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 {
969975
return ActionIter::new();
970976
};
971977
let l = self.len();
@@ -1908,13 +1914,13 @@ impl<'a, T> From<Merge<'a, T>> for Splice<'a, T, option::IntoIter<T>> {
19081914
}
19091915

19101916
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).
19181924
pub fn index(&self) -> usize {
19191925
self.current
19201926
}

crates/bevy_text/src/undo_2/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! Support for undo
2+
13
mod lib;
24
mod tests;
35

0 commit comments

Comments
 (0)