[][src]Struct scriptful::core::stack::Stack

pub struct Stack { /* fields omitted */ }

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.

Methods

impl Stack[src]

pub fn length(&self) -> usize[src]

Returns the number of values in the main sub-stack, also referred to as its 'length'.

Examples

use scriptful::prelude::*;
use scriptful::prelude::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

pub fn pop(&mut self) -> Value[src]

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

Panics

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

Examples

use scriptful::prelude::*;
use scriptful::prelude::Value::*;

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

assert_eq!(value, popped);Run

pub fn pop_into_alt(&mut self)[src]

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.

pub fn push(&mut self, item: Value)[src]

Puts a value on top of the stack.

Examples

use scriptful::prelude::*;
use scriptful::prelude::Value::*;

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

assert_eq!(value, *topmost);Run

pub fn push_from_alt(&mut self)[src]

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

Panics

Panics if there are no values left in the alt sub-stack.

pub fn topmost(&self) -> &Value[src]

Returns a reference to the last value in the main sub-stack.

Panics

Panics if there are no values left in the alt sub-stack.

Examples

use scriptful::prelude::*;
use scriptful::prelude::Value::*;

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

assert_eq!(value, *topmost);Run

Trait Implementations

impl Debug for Stack[src]

impl Default for Stack[src]

Auto Trait Implementations

impl Send for Stack

impl Sync for Stack

impl Unpin for Stack

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.