pub struct Acur<'a, T: Clone>(/* private fields */);Expand description
See also AcurBuilder.
§Sample code
use gur::prelude::*;
use gur::acur::{Acur, AcurBuilder};
// Appication state
#[derive(Clone)]
struct MyState {
data: String
}
fn main() {
// Initialize
let mut state = AcurBuilder::new().build(MyState{ data: "My".to_string() });
assert_eq!("My", state.data);
// Change state
state.edit(|mut state| { state.data += "State"; state });
assert_eq!("MyState", state.data);
// Undo
state.undo();
assert_eq!("My", state.data);
// Redo
state.redo();
assert_eq!("MyState", state.data);
}§Information
§Snapshot by Clone
Unlike Aur, Acur takes snapshots by Clone.
So Acur requires a type T implementing Clone instead of
Snapshot.
§Provided methods
Acur implements following undo-redo interfaces.
See the pages to view method list.
§Thread-safety
Trait Implementations§
Source§impl<'a, T: Clone> IEditA<'a> for Acur<'a, T>
impl<'a, T: Clone> IEditA<'a> for Acur<'a, T>
Source§impl<'a, T: Clone> IUndoRedo for Acur<'a, T>
impl<'a, T: Clone> IUndoRedo for Acur<'a, T>
Source§fn into_inner(self) -> T
fn into_inner(self) -> T
Returns the current state object, consuming the self.
Source§fn capacity(&self) -> Option<usize>
fn capacity(&self) -> Option<usize>
Returns the maximum number of changes stored in the history.
Source§fn undoable_count(&self) -> usize
fn undoable_count(&self) -> usize
Returns the number of versions older than current state in the history.
Source§fn redoable_count(&self) -> usize
fn redoable_count(&self) -> usize
Returns the number of versions newer than current state in the history.
Source§fn undo_multi(&mut self, count: usize) -> Option<&T>
fn undo_multi(&mut self, count: usize) -> Option<&T>
Undo multiple steps.
This method is more efficient than running
self.undo() multiple times. Read moreSource§fn redo_multi(&mut self, count: usize) -> Option<&T>
fn redo_multi(&mut self, count: usize) -> Option<&T>
Redo multiple steps.
This method is more efficient than running
self.redo() multiple times. Read moreSource§fn try_edit<F>(&mut self, command: F) -> Result<&T, Box<dyn Error>>
fn try_edit<F>(&mut self, command: F) -> Result<&T, Box<dyn Error>>
Takes a closure and update the internal state.
The closure consumes the current state and produces a new state or an error.
If the closure returns an error, the internal state is not changed. Read more
Source§fn undo(&mut self) -> Option<&Self::State>
fn undo(&mut self) -> Option<&Self::State>
Restores the previous state.
Same as
self.undo_multi(1). Read moreSource§fn redo(&mut self) -> Option<&Self::State>
fn redo(&mut self) -> Option<&Self::State>
Restores the next state.
Same as
self.redo_multi(1). Read moreAuto Trait Implementations§
impl<'a, T> Freeze for Acur<'a, T>where
T: Freeze,
impl<'a, T> RefUnwindSafe for Acur<'a, T>where
T: RefUnwindSafe,
impl<'a, T> Send for Acur<'a, T>where
T: Send,
impl<'a, T> Sync for Acur<'a, T>where
T: Sync,
impl<'a, T> Unpin for Acur<'a, T>where
T: Unpin,
impl<'a, T> UnwindSafe for Acur<'a, T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more