pub struct Stack { /* private fields */ }Expand description
A stack of Values.
Implementations§
source§impl Stack
impl Stack
sourcepub fn new(initial_capacity: usize, maximum_capacity: usize) -> Self
pub fn new(initial_capacity: usize, maximum_capacity: usize) -> Self
Returns a new stack with enough reserved space to store
initial_capacity values without reallocating and will not allow
pushing more than maximum_capacity values.
sourcepub fn push(&mut self, value: Value) -> Result<(), FaultKind>
pub fn push(&mut self, value: Value) -> Result<(), FaultKind>
Pushes value to the stack.
Errors
Returns FaultKind::StackOverflow if the stack’s maximum capacity has
been reached.
sourcepub fn extend<Args, ArgsIter>(&mut self, args: Args) -> Result<usize, FaultKind>where
Args: IntoIterator<Item = Value, IntoIter = ArgsIter>,
ArgsIter: Iterator<Item = Value> + ExactSizeIterator + DoubleEndedIterator,
pub fn extend<Args, ArgsIter>(&mut self, args: Args) -> Result<usize, FaultKind>where Args: IntoIterator<Item = Value, IntoIter = ArgsIter>, ArgsIter: Iterator<Item = Value> + ExactSizeIterator + DoubleEndedIterator,
Pushes multiple arguments to the stack.
sourcepub fn pop_n(&mut self, count: usize) -> PoppedValues<'_> ⓘ
pub fn pop_n(&mut self, count: usize) -> PoppedValues<'_> ⓘ
Pops count elements from the top of the stack.
This iterator returns the values in the sequence that they are ordered
on the stack, which is different than calling pop() count times
sequentially. For example, if the stack contains [0, 1, 2, 3], calling
pop() twice will result in 3, 2. Calling pop_n(2) will result in 2, 3.
sourcepub fn top(&self) -> Result<&Value, FaultKind>
pub fn top(&self) -> Result<&Value, FaultKind>
Returns a reference to the top Value on the stack, or returns a
FaultKind::StackUnderflow if no values are present.
sourcepub fn get(&self, index: usize) -> Result<&Value, FaultKind>
pub fn get(&self, index: usize) -> Result<&Value, FaultKind>
Returns a reference to the index Value from the end of the stack, or returns a
FaultKind::StackUnderflow if no value is present.
sourcepub fn top_mut(&mut self) -> Result<&mut Value, FaultKind>
pub fn top_mut(&mut self) -> Result<&mut Value, FaultKind>
Returns a reference to the top Value on the stack, or returns a
FaultKind::StackUnderflow if no values are present.
sourcepub fn truncate(&mut self, new_length: usize)
pub fn truncate(&mut self, new_length: usize)
Truncates the stack to new_length. If the new_length is larger than
the current length, this function does nothing.
sourcepub const fn remaining_capacity(&self) -> usize
pub const fn remaining_capacity(&self) -> usize
Returns the number of Values that can be pushed to this stack before
a FaultKind::StackOverflow is raised.