Acur

Struct Acur 

Source
pub struct Acur<'a, T: Clone>(/* private fields */);
Expand description

Cur + Send + Sync

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

Acur implements Send and Sync.

Trait Implementations§

Source§

impl<'a, T: Debug + Clone> Debug for Acur<'a, T>

Source§

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

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

impl<'a, T: Clone> Deref for Acur<'a, T>

Source§

type Target = T

The resulting type after dereferencing.
Source§

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

Dereferences the value.
Source§

impl<'a, T: Clone + Display> Display for Acur<'a, T>

Source§

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

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

impl<'a, T: Clone> IEditA<'a> for Acur<'a, T>

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: Clone> IUndoRedo for Acur<'a, T>

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> 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> 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.