pub struct FromFn<F, T> { /* private fields */ }
Expand description
Action made from a function.
Examples
let mut target = String::new();
let mut record = Record::new();
let a: fn(&mut String) = |s| s.push('a');
let b: fn(&mut String) = |s| s.push('b');
record.apply(&mut target, FromFn::new(a));
record.apply(&mut target, FromFn::new(b));
assert_eq!(target, "ab");
record.undo(&mut target);
record.undo(&mut target);
assert_eq!(target, "");
record.redo(&mut target);
record.redo(&mut target);
assert_eq!(target, "ab");
Implementations§
Trait Implementations§
source§impl<F, T> Action for FromFn<F, T>where
F: FnMut(&mut T),
T: Clone,
impl<F, T> Action for FromFn<F, T>where F: FnMut(&mut T), T: Clone,
source§fn apply(&mut self, target: &mut Self::Target) -> Self::Output
fn apply(&mut self, target: &mut Self::Target) -> Self::Output
Applies the action on the target.
source§fn undo(&mut self, target: &mut Self::Target) -> Self::Output
fn undo(&mut self, target: &mut Self::Target) -> Self::Output
Restores the state of the target as it was before the action was applied.