Expand description
An ordered sequence of values that can be operated in a LIFO-alike way.
Every Stack
actually comprises two sequences of values: the main
sub-stack and the alt
sub-stack.
As its name indicates, the main
sub-stack is the one you operate by default.
That is, the alt
sub-stack cannot be operated directly — you can only move values between both sub-stacks with the pop_into_alt
and push_from_alt
methods.
The alt
sub-stack is therefore limited for usage as a sort of clipboard for values.
Implementations
sourceimpl<Val> Stack<Val> where
Val: Debug,
impl<Val> Stack<Val> where
Val: Debug,
sourcepub fn length(&self) -> usize
pub fn length(&self) -> usize
Returns the number of values in the main
sub-stack, also referred to as its ‘length’.
Examples
use scriptful::prelude::*;
use scriptful::core::value::Value::*;
let mut stack = Stack::default();
assert_eq!(stack.length(), 0);
stack.push(Integer(i128::default()));
assert_eq!(stack.length(), 1);
stack.pop();
assert_eq!(stack.length(), 0);
Runsourcepub fn pop_into_alt(&mut self)
pub fn pop_into_alt(&mut self)
sourcepub fn push_from_alt(&mut self)
pub fn push_from_alt(&mut self)
Similar to push
, but instead of receiving the value to be pushed as an argument, it pops it from the alt
sub-stack.
sourcepub fn topmost(&self) -> Option<&Val>
pub fn topmost(&self) -> Option<&Val>
Returns a reference to the last value in the main
sub-stack.
Examples
use scriptful::prelude::*;
use scriptful::core::value::Value::*;
let value = Integer(i128::default());
let mut stack = Stack::default();
stack.push(value.clone());
let topmost = stack.topmost();
assert_eq!(topmost, Some(&value));
RunTrait Implementations
Auto Trait Implementations
impl<Val> RefUnwindSafe for Stack<Val> where
Val: RefUnwindSafe,
impl<Val> Send for Stack<Val> where
Val: Send,
impl<Val> Sync for Stack<Val> where
Val: Sync,
impl<Val> Unpin for Stack<Val> where
Val: Unpin,
impl<Val> UnwindSafe for Stack<Val> where
Val: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more