pub struct Stack<Val = Value> where
    Val: Debug
{ /* private fields */ }
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

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);
Run

Removes the topmost value in the main sub-stack and returns it.

Examples
use scriptful::prelude::*;
use scriptful::core::value::Value::*;

let value = Integer(i128::default());
let mut stack = Stack::default();
stack.push(value.clone());
let popped = stack.pop();

assert_eq!(value, popped);
Run

Similar to pop, but instead of returning the popped value, it pushes it to the alt sub-stack.

Panics

Panics if there are no values left in the main stack.

Puts a value on top of the 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));
Run

Similar to push, but instead of receiving the value to be pushed as an argument, it pops it from the alt sub-stack.

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));
Run

Trait Implementations

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.