Skip to content

Commit 63894b7

Browse files
committed
Clippy
1 parent dcaa00b commit 63894b7

File tree

4 files changed

+53
-52
lines changed

4 files changed

+53
-52
lines changed

crates/bevy_text/src/undo_2/lib.rs

Lines changed: 48 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@ use core::iter::FusedIterator;
66
use core::ops::ControlFlow;
77
use core::ops::{Deref, Index};
88
use core::option;
9-
use std::fmt::Debug;
9+
use core::fmt::Debug;
1010
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};
1313

1414
#[cfg(feature = "serde")]
1515
use serde::{Deserialize, Serialize};
1616

1717
/// Action that should be taken on the paired command
1818
///
19-
/// [ActionIter] item type is a pair `(Action, C)` where
19+
/// [`ActionIter`] item type is a pair `(Action, C)` where
2020
/// C is the client defined command type. `(Action::Do, t)`
2121
/// signifies that the command `t` shall be executed. `(Action::Undo,t)`
2222
/// means it shall be undone.
@@ -50,24 +50,24 @@ pub enum Action<T> {
5050
/// transition are interlieved with other transitions.
5151
///
5252
/// 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.
5454
/// It is supposed to be used as the element of the [Commands]:
5555
/// `Commands<SetOrTransition::<MyStateCommands,MyTransitions>`.
5656
///
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
5858
/// commands partitionned in independent state and transitions.
5959
///
6060
/// State commands are supposed to represent the setting of an indepent state such as "set the view
6161
/// 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
6363
/// command the application of it.
6464
///
6565
/// # Example
6666
///
6767
/// In this example we use commands that set the state `color` and `length`.
6868
///
6969
/// 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.
7171
/// ```
7272
/// use std::mem::{discriminant, Discriminant};
7373
///
@@ -200,7 +200,7 @@ pub trait IndepStateKey {
200200
}
201201

202202
/// The actions asked to be performed by the user
203-
/// when calling [Commands::apply_actions]
203+
/// when calling [`Commands::apply_actions`]
204204
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
205205
pub enum SetTransAction<'a, S: IndepStateKey, T> {
206206
/// Ask the execution of the transition .0
@@ -320,7 +320,7 @@ pub enum CommandItem<T> {
320320
///
321321
/// # Representation
322322
///
323-
/// `Commands` owns a slice of [CommandItem] that is accesible
323+
/// `Commands` owns a slice of [`CommandItem`] that is accesible
324324
/// by dereferencing the command.
325325
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
326326
#[derive(Eq)]
@@ -330,7 +330,7 @@ pub struct Commands<T> {
330330
undo_cache: Vec<IndexedAction>,
331331
}
332332
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 {
334334
f.debug_struct("Commands")
335335
.field("commands", &self.commands)
336336
.finish()
@@ -342,7 +342,7 @@ impl<T: PartialEq> PartialEq for Commands<T> {
342342
}
343343
}
344344
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) {
346346
self.commands.hash(state);
347347
}
348348
}
@@ -368,11 +368,11 @@ struct IndexedAction {
368368
index: usize,
369369
}
370370

371-
/// Specify a merge when calling [Commands::merge](Commands#method.merge)
371+
/// Specify a merge when calling [`Commands::merge`](Commands#method.merge)
372372
///
373373
/// The [`end`, `start`) bounds the slice of command that will
374374
/// be removed during the merge. `end` and `start` are in reverse order
375-
/// because [IterRealized] goes backward.
375+
/// because [`IterRealized`] goes backward.
376376
///
377377
/// If `command` is `None` then the slice will be removed, otherwise if
378378
/// the `command` is `Some(c)` the slice will be replace by `c`.
@@ -383,11 +383,11 @@ pub struct Merge<'a, T> {
383383
pub command: Option<T>,
384384
}
385385

386-
/// Specify a splice when calling [Commands::splice](Commands#method.splice)
386+
/// Specify a splice when calling [`Commands::splice`](Commands#method.splice)
387387
///
388388
/// The [`end`, `start`) bounds the slice of command that will
389389
/// be removed during the merge. `end` and `start` are in reverse order
390-
/// because [IterRealized] goes backward.
390+
/// because [`IterRealized`] goes backward.
391391
///
392392
/// The removed slice is then replaced by the sequence (not reversed) of
393393
/// commands denoted by `commands`.
@@ -399,8 +399,8 @@ pub struct Splice<'a, T, I: IntoIterator<Item = T>> {
399399
}
400400

401401
#[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)
404404
pub struct ActionIter<'a, T> {
405405
commands: &'a [CommandItem<T>],
406406
to_do: slice::Iter<'a, IndexedAction>,
@@ -415,7 +415,7 @@ impl<T> Clone for ActionIter<'_, T> {
415415
}
416416

417417
#[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).
419419
pub struct IterRealized<'a, T> {
420420
commands: &'a [CommandItem<T>],
421421
current: usize,
@@ -427,17 +427,17 @@ impl<T> Clone for IterRealized<'_, T> {
427427
}
428428

429429
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
431431
/// by argument `f`.
432432
///
433433
/// The list of action to be applied are provided by the call of `act` on
434434
/// this [Commands]. This may be defined, for exemple as, `|c| c.redo()`
435435
///
436-
/// This command only exist when the commands have the type [SetOrTransition].
436+
/// This command only exist when the commands have the type [`SetOrTransition`].
437437
/// See the documentation of this type for an explanation.
438438
///
439439
/// 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]
441441
/// (most probably only once) per [key][IndepStateKey::key] for commands that represent independent state setting.
442442
pub fn apply_actions(
443443
&mut self,
@@ -446,17 +446,17 @@ impl<S: IndepStateKey, T> Commands<SetOrTransition<S, T>> {
446446
) {
447447
let mut state_commands = Vec::new();
448448
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);
450450
}
451451
self.restore_state(state_commands, f);
452452
}
453453
/// Equivalent to `apply_actions(|c| c.undo(),f)`.
454454
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);
456456
}
457457
/// Equivalent to `apply_actions(|c| c.redo(),f)`.
458458
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);
460460
}
461461
fn apply_action(
462462
action: Action<&SetOrTransition<S, T>>,
@@ -467,7 +467,7 @@ impl<S: IndepStateKey, T> Commands<SetOrTransition<S, T>> {
467467
Action::Do(SetOrTransition::Transition(tr)) => f(SetTransAction::Do(tr)),
468468
Action::Undo(SetOrTransition::Transition(tr)) => f(SetTransAction::Undo(tr)),
469469
Action::Do(SetOrTransition::Set(s)) | Action::Undo(SetOrTransition::Set(s)) => {
470-
state_keys.push(Some(s.key()))
470+
state_keys.push(Some(s.key()));
471471
}
472472
}
473473
}
@@ -511,7 +511,7 @@ impl<S: IndepStateKey, T> Commands<SetOrTransition<S, T>> {
511511
}
512512
if l > 0 {
513513
for disc in state_keys.into_iter().flatten() {
514-
f(SetTransAction::SetToInitial(disc))
514+
f(SetTransAction::SetToInitial(disc));
515515
}
516516
}
517517
}
@@ -531,7 +531,7 @@ impl<T> Commands<T> {
531531
}
532532
/// Reserve space for new commands
533533
pub fn reserve(&mut self, additional: usize) {
534-
self.commands.reserve(additional)
534+
self.commands.reserve(additional);
535535
}
536536

537537
/// Return a reference to the last command
@@ -691,7 +691,7 @@ impl<T> Commands<T> {
691691
producer: impl FnOnce() -> T,
692692
) {
693693
if !self.update_last(updater) {
694-
self.push(producer())
694+
self.push(producer());
695695
}
696696
}
697697

@@ -1181,7 +1181,7 @@ impl<T> Commands<T> {
11811181
}
11821182

11831183
/// Repeat undo or redo so that the last realiazed command correspond to
1184-
/// the [CommandItem] index passed `index`.
1184+
/// the [`CommandItem`] index passed `index`.
11851185
///
11861186
/// ```
11871187
/// use crate::undo_2::{Action,Commands, CommandItem};
@@ -1337,7 +1337,7 @@ impl<T> Commands<T> {
13371337
CommandItem::Undo(_) => false,
13381338
CommandItem::Command(c) => stop_pred(c),
13391339
}) {
1340-
self.remove_first(i)
1340+
self.remove_first(i);
13411341
}
13421342
}
13431343
/// Try to keep `count` most recent commands by dropping removable commands.
@@ -1404,7 +1404,7 @@ impl<T> Commands<T> {
14041404
/// ```
14051405
pub fn keep_last(&mut self, count: usize) {
14061406
let i = self.len().saturating_sub(count);
1407-
self.remove_first(i)
1407+
self.remove_first(i);
14081408
}
14091409
/// Remove `count` or less of the oldest command.
14101410
///
@@ -1479,11 +1479,10 @@ impl<T> Commands<T> {
14791479
fn remove_i(&self, mut i: usize, end: usize) -> usize {
14801480
let i0 = i;
14811481
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);
14851485
}
1486-
}
14871486
}
14881487
i
14891488
}
@@ -1538,7 +1537,7 @@ impl<T> Commands<T> {
15381537
/// Merge a sequence of [*realized commands*](Commands#method.iter_realized) into a single new
15391538
/// command or remove the sequence.
15401539
///
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
15421541
/// [`std::ops::ControlFlow<Option<Merge>, Option<Merge>>`](std::ops::ControlFlow). If the
15431542
/// returned value contain a `Some(merge)`[Merge], the action specified by `merge` is then
15441543
/// inserted in place.
@@ -1598,15 +1597,15 @@ impl<T> Commands<T> {
15981597
{
15991598
use ControlFlow::*;
16001599
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+
});
16041603
}
16051604

16061605
/// 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)
16081607
///
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
16101609
/// [`std::ops::ControlFlow<Option<Splice>, Option<Splice>>`](std::ops::ControlFlow). If the returned value
16111610
/// contain a `Some(splice)`[Splice], the actions specified by `splice` are then inserted in
16121611
/// place.
@@ -1705,7 +1704,7 @@ impl<T> Commands<T> {
17051704
let end_i = rev_start;
17061705
let start_i = rev_end;
17071706
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));
17091708
}
17101709

17111710
/// Clean up the history of all the undone commands.
@@ -1736,7 +1735,7 @@ impl<T> Commands<T> {
17361735
/// assert_eq!(*c, [A.into(), C.into()]);
17371736
/// ```
17381737
pub fn remove_all_undone(&mut self) {
1739-
self.remove_undone(|i| i)
1738+
self.remove_undone(|i| i);
17401739
}
17411740
/// Clean up the history of all undone commands before a given
17421741
/// [realized iterator](Commands#method.iter_realized).
@@ -1833,7 +1832,7 @@ impl<T: Clone> Clone for Commands<T> {
18331832
}
18341833
}
18351834
fn clone_from(&mut self, source: &Self) {
1836-
self.commands.clone_from(&source.commands)
1835+
self.commands.clone_from(&source.commands);
18371836
}
18381837
}
18391838

@@ -1855,13 +1854,13 @@ impl<T> Borrow<[CommandItem<T>]> for Commands<T> {
18551854
}
18561855
impl<T> Extend<T> for Commands<T> {
18571856
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));
18591858
}
18601859
}
18611860
impl<T> FromIterator<T> for Commands<T> {
18621861
fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self {
18631862
Self {
1864-
commands: iter.into_iter().map(|c| c.into()).collect(),
1863+
commands: iter.into_iter().map(Into::into).collect(),
18651864
undo_cache: vec![],
18661865
}
18671866
}
@@ -2066,14 +2065,14 @@ fn do_simplify(to_do: &mut [IndexedAction]) {
20662065
if to_do[cursor].is_reverse_of(action) {
20672066
cursor += 1;
20682067
while cursor < l && to_do[cursor].action == Skip {
2069-
cursor += 1
2068+
cursor += 1;
20702069
}
20712070
} else {
20722071
to_do[analyzed + 1..cursor]
20732072
.iter_mut()
20742073
.for_each(|a| a.action = Skip);
20752074
if cursor == analyzed + 1 {
2076-
cursor = analyzed
2075+
cursor = analyzed;
20772076
} else {
20782077
cursor = analyzed + 1;
20792078
analyzed += 1;

crates/bevy_text/src/undo_2/tests/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#[expect(clippy::allow_attributes_without_reason)]
2+
13
mod iter_realized;
24
mod merge;
35
mod redo;

crates/bevy_text/src/undo_2/tests/set_and_transition.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::mem::{discriminant, Discriminant};
1+
use core::mem::{discriminant, Discriminant};
22

33
use crate::undo_2::{IndepStateKey, SetTransAction};
44

crates/bevy_text/src/undo_2/tests/splice.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#![allow(unused)]
22

33
use crate::undo_2::*;
4-
use std::ops::ControlFlow;
4+
use core::ops::ControlFlow;
55

66
#[derive(PartialEq, Debug)]
77
enum Command {
@@ -29,7 +29,7 @@ fn do_splice(c: &mut Commands<Command>) {
2929
} else {
3030
ControlFlow::Continue(None)
3131
}
32-
})
32+
});
3333
}
3434

3535
#[test]

0 commit comments

Comments
 (0)