Aur

Struct Aur 

Source
pub struct Aur<'a, T, S>(/* private fields */)
where
    T: Snapshot<Snapshot = S>;
Expand description

Ur + Send + Sync

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

Aur implements Send and Sync.

Trait Implementations§

Source§

impl<'a, T, S> Debug for Aur<'a, T, S>
where T: Snapshot<Snapshot = S> + Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl<'a, T, S> Deref for Aur<'a, T, S>
where T: Snapshot<Snapshot = S>,

Source§

type Target = T

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<'a, T, S> Display for Aur<'a, T, S>
where T: Snapshot<Snapshot = S> + Display,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl<'a, T, S> IEditA<'a> for Aur<'a, T, S>
where T: Snapshot<Snapshot = S>,

Source§

type State = T

A type of state managed in Self.
Source§

fn edit_if<F>(&mut self, command: F) -> Option<&T>
where F: Fn(T) -> Option<T> + Send + Sync + 'a,

Takes a closure and update the internal state. The closure consumes the current state and produces a new state or None. If the closure returns None, the internal state is not changed. Read more
Source§

fn edit<F>(&mut self, command: F) -> &Self::State
where F: Fn(Self::State) -> Self::State + Send + Sync + 'a,

Takes a closure and update the internal state. The closure consumes the current state and produces a new state. Read more
Source§

impl<'a, T, S> IUndoRedo for Aur<'a, T, S>
where T: Snapshot<Snapshot = S>,

Source§

type State = T

A type of state managed in Self.
Source§

fn into_inner(self) -> T

Returns the current state object, consuming the self.
Source§

fn capacity(&self) -> Option<usize>

Returns the maximum number of changes stored in the history.
Source§

fn undoable_count(&self) -> usize

Returns the number of versions older than current state in the history.
Source§

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>

Undo multiple steps. This method is more efficient than running self.undo() multiple times. Read more
Source§

fn redo_multi(&mut self, count: usize) -> Option<&T>

Redo multiple steps. This method is more efficient than running self.redo() multiple times. Read more
Source§

fn try_edit<F>(&mut self, command: F) -> Result<&T, Box<dyn Error>>
where F: FnOnce(T) -> 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>

Restores the previous state. Same as self.undo_multi(1). Read more
Source§

fn redo(&mut self) -> Option<&Self::State>

Restores the next state. Same as self.redo_multi(1). Read more
Source§

fn jump(&mut self, count: isize) -> Option<&Self::State>

Undo-redo bidirectionally. This is integrated method of undo_multi and redo_multi. Read more

Auto 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>
where T: Send, S: Send,

§

impl<'a, T, S> Sync for Aur<'a, T, S>
where T: Sync, S: Sync,

§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.