[−][src]Function undo::from_fn
pub fn from_fn<T, F>(f: F) -> FromFn<T, F>
Creates a command from the provided function.
The undo functionality is provided by cloning the original data before editing it.
Examples
let mut record = Record::default(); record.apply(from_fn(|s: &mut String| s.push('a')))?; record.apply(from_fn(|s: &mut String| s.push('b')))?; record.apply(from_fn(|s: &mut String| s.push('c')))?; assert_eq!(record.target(), "abc"); record.undo()?; record.undo()?; record.undo()?; assert_eq!(record.target(), ""); record.redo()?; record.redo()?; record.redo()?; assert_eq!(record.target(), "abc");