pub struct Aur<'a, T, S>(/* private fields */)
where
T: Snapshot<Snapshot = S>;Expand description
See also AurBuilder.
§Sample code
use gur::prelude::*;
use gur::aur::{Aur, AurBuilder};
use gur::snapshot::Snapshot;
// Appication state
#[derive(Clone)]
struct MyState {
data: String
}
// Implementing Snapshot trait
impl Snapshot for MyState {
type Snapshot = String;
fn to_snapshot(&self) -> Self::Snapshot {
self.data.clone()
}
fn from_snapshot(snapshot: &Self::Snapshot) -> Self {
MyState{ data: snapshot.clone() }
}
}
fn main() {
// Initialize
let mut state = AurBuilder::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 trait
Aur requires a type T implementing Snapshot.
The trait specifies conversion between T and its snapshot object.
Acur may be more suitable for simple types. It requires Clone instead of Snapshot. See Acur for more detail.
§Provided methods
Aur implements following undo-redo interfaces.
See the pages to view method list.
§Thread-safety
Trait Implementations§
Source§impl<'a, T, S> IEditA<'a> for Aur<'a, T, S>where
T: Snapshot<Snapshot = S>,
impl<'a, T, S> IEditA<'a> for Aur<'a, T, S>where
T: Snapshot<Snapshot = S>,
Source§impl<'a, T, S> IUndoRedo for Aur<'a, T, S>where
T: Snapshot<Snapshot = S>,
impl<'a, T, S> IUndoRedo for Aur<'a, T, S>where
T: Snapshot<Snapshot = S>,
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, S> Freeze for Aur<'a, T, S>where
T: Freeze,
impl<'a, T, S> RefUnwindSafe for Aur<'a, T, S>where
T: RefUnwindSafe,
impl<'a, T, S> Send for Aur<'a, T, S>
impl<'a, T, S> Sync for Aur<'a, T, S>
impl<'a, T, S> Unpin for Aur<'a, T, S>where
T: Unpin,
impl<'a, T, S> UnwindSafe for Aur<'a, T, S>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