[−][src]Struct undo::Queue
A command queue wrapper.
Wraps a Record or History and gives it batch queue functionality.
Examples
#[derive(Debug)] struct Add(char); impl Command<String> for Add { fn apply(&mut self, s: &mut String) -> undo::Result { s.push(self.0); Ok(()) } fn undo(&mut self, s: &mut String) -> undo::Result { self.0 = s.pop().ok_or("`s` is empty")?; Ok(()) } } fn main() -> undo::Result { let mut record = Record::default(); let mut queue = record.queue(); queue.apply(Add('a')); queue.apply(Add('b')); queue.apply(Add('c')); assert_eq!(queue.as_receiver(), ""); queue.commit()?; assert_eq!(record.as_receiver(), "abc"); Ok(()) }
Methods
impl<'a, T, R> Queue<'a, T, R>
[src]
impl<'a, T, R> Queue<'a, T, R>
pub fn new(inner: &'a mut T) -> Queue<'a, T, R> | [src] |
Returns a queue.
pub fn reserve(&mut self, additional: usize) | [src] |
Reserves capacity for at least additional
more commands in the queue.
Panics
Panics if the new capacity overflows usize.
pub fn capacity(&self) -> usize | [src] |
Returns the capacity of the queue.
pub fn len(&self) -> usize | [src] |
Returns the number of commands in the queue.
pub fn is_empty(&self) -> bool | [src] |
Returns true
if the queue is empty.
pub fn apply( | [src] |
Queues an apply
action.
pub fn undo(&mut self) | [src] |
Queues an undo
action.
pub fn redo(&mut self) | [src] |
Queues a redo
action.
pub fn cancel(self) | [src] |
Cancels the queued actions.
impl<R, '_> Queue<'_, Record<R>, R>
[src]
impl<R, '_> Queue<'_, Record<R>, R>
pub fn go_to(&mut self, cursor: usize) | [src] |
Queues a go_to
action.
pub fn commit(self) -> Result where | [src] |
Applies the actions that is queued.
Errors
If an error occurs, it stops applying the actions and returns the error.
pub fn checkpoint(&mut self) -> Checkpoint<Record<R>, R> | [src] |
Returns a checkpoint.
pub fn queue(&mut self) -> Queue<Record<R>, R> | [src] |
Returns a queue.
pub fn as_receiver(&self) -> &R | [src] |
Returns a reference to the receiver
.
pub fn as_mut_receiver(&mut self) -> &mut R | [src] |
Returns a mutable reference to the receiver
.
This method should only be used when doing changes that should not be able to be undone.
impl<R, '_> Queue<'_, History<R>, R>
[src]
impl<R, '_> Queue<'_, History<R>, R>
pub fn go_to(&mut self, branch: usize, cursor: usize) | [src] |
Queues a go_to
action.
pub fn commit(self) -> Result where | [src] |
Applies the actions that is queued.
Errors
If an error occurs, it stops applying the actions and returns the error.
pub fn checkpoint(&mut self) -> Checkpoint<History<R>, R> | [src] |
Returns a checkpoint.
pub fn queue(&mut self) -> Queue<History<R>, R> | [src] |
Returns a queue.
pub fn as_receiver(&self) -> &R | [src] |
Returns a reference to the receiver
.
pub fn as_mut_receiver(&mut self) -> &mut R | [src] |
Returns a mutable reference to the receiver
.
This method should only be used when doing changes that should not be able to be undone.
Trait Implementations
impl<R, '_> AsRef<R> for Queue<'_, Record<R>, R>
[src]
impl<R, '_> AsRef<R> for Queue<'_, Record<R>, R>
impl<R, '_> AsRef<R> for Queue<'_, History<R>, R>
[src]
impl<R, '_> AsRef<R> for Queue<'_, History<R>, R>
impl<T, R: 'static, C: Command<R> + 'static, '_> Extend<C> for Queue<'_, T, R>
[src]
impl<T, R: 'static, C: Command<R> + 'static, '_> Extend<C> for Queue<'_, T, R>
fn extend<I: IntoIterator<Item = C>>(&mut self, commands: I) | [src] |
impl<'a, T, R> From<&'a mut T> for Queue<'a, T, R>
[src]
impl<'a, T, R> From<&'a mut T> for Queue<'a, T, R>
impl<R, '_> AsMut<R> for Queue<'_, Record<R>, R>
[src]
impl<R, '_> AsMut<R> for Queue<'_, Record<R>, R>
impl<R, '_> AsMut<R> for Queue<'_, History<R>, R>
[src]
impl<R, '_> AsMut<R> for Queue<'_, History<R>, R>
impl<'a, T: Debug, R: Debug> Debug for Queue<'a, T, R>
[src]
impl<'a, T: Debug, R: Debug> Debug for Queue<'a, T, R>
Auto Trait Implementations
impl<'a, T, R> Send for Queue<'a, T, R> where
T: Send,
impl<'a, T, R> Send for Queue<'a, T, R> where
T: Send,
impl<'a, T, R> Sync for Queue<'a, T, R> where
T: Sync,
impl<'a, T, R> Sync for Queue<'a, T, R> where
T: Sync,
Blanket Implementations
impl<T> From for T
[src]
impl<T> From for T
impl<T, U> Into for T where
U: From<T>,
[src]
impl<T, U> Into for T where
U: From<T>,
impl<T, U> TryFrom for T where
T: From<U>,
[src]
impl<T, U> TryFrom for T where
T: From<U>,
type Error = !
try_from
)The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error> | [src] |
impl<T> Borrow for T where
T: ?Sized,
[src]
impl<T> Borrow for T where
T: ?Sized,
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
impl<T, U> TryInto for T where
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
try_from
)The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error> | [src] |
impl<T> BorrowMut for T where
T: ?Sized,
[src]
impl<T> BorrowMut for T where
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T | [src] |
impl<T> Any for T where
T: 'static + ?Sized,
[src]
impl<T> Any for T where
T: 'static + ?Sized,
fn get_type_id(&self) -> TypeId | [src] |