Struct redo::RedoGroup [] [src]

pub struct RedoGroup<'a, T> { /* fields omitted */ }

A collection of RedoStacks.

A RedoGroup is useful when working with multiple stacks and only one of them should be active at a given time, eg. a text editor with multiple documents opened. However, if only a single stack is needed, it is easier to just use the stack directly.

Methods

impl<'a, T> RedoGroup<'a, T>
[src]

Creates a new RedoGroup.

Examples

let group = RedoGroup::<PopCmd>::new();

Creates a new RedoGroup with the specified capacity.

Examples

let group = RedoGroup::<PopCmd>::with_capacity(10);
assert!(group.capacity() >= 10);

Returns the capacity of the RedoGroup.

Examples

let group = RedoGroup::<PopCmd>::with_capacity(10);
assert!(group.capacity() >= 10);

Reserves capacity for at least additional more stacks to be inserted in the given group. The group may reserve more space to avoid frequent reallocations.

Panics

Panics if the new capacity overflows usize.

Examples

let mut group = RedoGroup::<PopCmd>::new();
group.add_default();
group.reserve(10);
assert!(group.capacity() >= 11);

Shrinks the capacity of the RedoGroup as much as possible.

Examples

let mut group = RedoGroup::<PopCmd>::with_capacity(10);
group.add_default();
group.add_default();
group.add_default();

assert!(group.capacity() >= 10);
group.shrink_to_fit();
assert!(group.capacity() >= 3);

Adds an RedoStack to the group and returns an unique id for this stack.

Examples

let mut group = RedoGroup::<PopCmd>::new();
let a = group.add_default();
let b = group.add_default();
let c = group.add_default();

Removes the RedoStack with the specified id and returns the stack. Returns None if the stack was not found.

Examples

let mut group = RedoGroup::<PopCmd>::new();
let a = group.add_default();
let stack = group.remove(a);
assert!(stack.is_some());

Sets the RedoStack with the specified id as the current active one.

Examples

let mut group = RedoGroup::<PopCmd>::new();
let a = group.add_default();
group.set_active(a);

Clears the current active RedoStack.

Examples

let mut group = RedoGroup::<PopCmd>::new();
let a = group.add_default();
group.set_active(a);
group.clear_active();

Calls is_clean on the active RedoStack, if there is one. Returns None if there is no active stack.

Examples

let mut vec = vec![1, 2, 3];
let mut group = RedoGroup::new();
let cmd = PopCmd { vec: &mut vec, e: None };

let a = group.add(RedoStack::new());
assert_eq!(group.is_clean(), None);
group.set_active(a);

assert_eq!(group.is_clean(), Some(true)); // An empty stack is always clean.
group.push(cmd);
assert_eq!(group.is_clean(), Some(true));
group.undo();
assert_eq!(group.is_clean(), Some(false));

Calls is_dirty on the active RedoStack, if there is one. Returns None if there is no active stack.

Examples

let mut vec = vec![1, 2, 3];
let mut group = RedoGroup::new();
let cmd = PopCmd { vec: &mut vec, e: None };

let a = group.add(RedoStack::new());
assert_eq!(group.is_dirty(), None);
group.set_active(a);

assert_eq!(group.is_dirty(), Some(false)); // An empty stack is always clean.
group.push(cmd);
assert_eq!(group.is_dirty(), Some(false));
group.undo();
assert_eq!(group.is_dirty(), Some(true));

impl<'a, T: RedoCmd> RedoGroup<'a, T>
[src]

Calls push on the active RedoStack, if there is one.

Returns Some(Ok) if everything went fine, Some(Err) if something went wrong, and None if there is no active stack.

Examples

let mut vec = vec![1, 2, 3];
let mut group = RedoGroup::new();
let cmd = PopCmd { vec: &mut vec, e: None };

let a = group.add(RedoStack::new());
group.set_active(a);

group.push(cmd);
group.push(cmd);
group.push(cmd);

assert!(vec.is_empty());

Calls redo on the active RedoStack, if there is one.

Returns Some(Ok) if everything went fine, Some(Err) if something went wrong, and None if there is no active stack.

Examples

let mut vec = vec![1, 2, 3];
let mut group = RedoGroup::new();
let cmd = PopCmd { vec: &mut vec, e: None };

let a = group.add(RedoStack::new());
group.set_active(a);

group.push(cmd);
group.push(cmd);
group.push(cmd);

assert!(vec.is_empty());

group.undo();
group.undo();
group.undo();

assert_eq!(vec, vec![1, 2, 3]);

group.redo();
group.redo();
group.redo();

assert!(vec.is_empty());

Calls undo on the active RedoStack, if there is one.

Returns Some(Ok) if everything went fine, Some(Err) if something went wrong, and None if there is no active stack.

Examples

let mut vec = vec![1, 2, 3];
let mut group = RedoGroup::new();
let cmd = PopCmd { vec: &mut vec, e: None };

let a = group.add(RedoStack::new());
group.set_active(a);

group.push(cmd);
group.push(cmd);
group.push(cmd);

assert!(vec.is_empty());

group.undo();
group.undo();
group.undo();

assert_eq!(vec, vec![1, 2, 3]);

impl<'a, T: Default> RedoGroup<'a, T>
[src]

Adds a default RedoStack to the group and returns an unique id for this stack.

Examples

let mut group = RedoGroup::<PopCmd>::new();
let a = group.add_default();
let b = group.add_default();
let c = group.add_default();

Trait Implementations

impl<'a, T: Default> Default for RedoGroup<'a, T>
[src]

Returns the "default value" for a type. Read more

impl<'a, T: Debug> Debug for RedoGroup<'a, T>
[src]

Formats the value using the given formatter.