pub struct HistoryStack<T> { /* private fields */ }
Expand description
A wrapper over a T
that provides a primitive history mechanism by use of a stack of T
. It
can be pushed to or popped from to save the current value or pop out a previously saved value
in LIFO (stack) order.
HistoryStack
is also “transparently T”, meaning the default traits it implements all act like
the current value of T, so hashing HistoryStack<T>
and T produce the same hash, Eq and Ord work
the same etc. This also includes Display
, but does not include Debug
.
Implementations§
Source§impl<T> HistoryStack<T>
impl<T> HistoryStack<T>
Sourcepub const fn new(v: T) -> Self
pub const fn new(v: T) -> Self
Create a new HistoryStack
whose current value is set to v
, with no history
Sourcepub fn pop(&mut self) -> Option<T>
pub fn pop(&mut self) -> Option<T>
Pop a value from the stack and set it as the current value, returning the previous current value.
Returns None
in the case that there was no previous value from the stack, current is also
unchanged.
Sourcepub fn push_value(&mut self, v: T)
pub fn push_value(&mut self, v: T)
Pushes a value into the current value, and pushes the previously current value into the stack.
Sourcepub fn push(&mut self)where
T: Clone,
pub fn push(&mut self)where
T: Clone,
Makes a Clone::clone
of the current value and pushes it to the stack, leaving the
current value untouched
Trait Implementations§
Source§impl<T: Clone> Clone for HistoryStack<T>
impl<T: Clone> Clone for HistoryStack<T>
Source§fn clone(&self) -> HistoryStack<T>
fn clone(&self) -> HistoryStack<T>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more