Trait StackOperations

Source
pub trait StackOperations {
    // Required methods
    fn push(&mut self, value: Value);
    fn pop(&mut self) -> Option<Value>;
    fn peek(&self) -> Option<&Value>;
    fn clear(&mut self);
    fn len(&self) -> usize;
    fn is_empty(&self) -> bool;
    fn stack_mut(&mut self) -> &mut Stack;

    // Provided method
    fn size(&self) -> usize { ... }
}
Expand description

Defines operations for manipulating the VM’s operand stack

This trait provides the interface for all stack operations including pushing, popping, and inspecting stack contents.

Required Methods§

Source

fn push(&mut self, value: Value)

Pushes a value onto the top of the stack

§Arguments
  • value - The value to push onto the stack
Source

fn pop(&mut self) -> Option<Value>

Pops a value from the top of the stack

§Returns
  • Some(value) if the stack is not empty
  • None if the stack is empty
Source

fn peek(&self) -> Option<&Value>

Peeks at the top value without removing it

§Returns
  • Some(&value) if the stack is not empty
  • None if the stack is empty
Source

fn clear(&mut self)

Clears all values from the stack

Source

fn len(&self) -> usize

Gets the current number of values on the stack

§Returns
  • The number of values currently on the stack
Source

fn is_empty(&self) -> bool

Checks if the stack is empty

§Returns
  • true if the stack contains no values
  • false if the stack contains at least one value
Source

fn stack_mut(&mut self) -> &mut Stack

Gets a mutable reference to the underlying stack

This allows direct access to the stack for advanced operations that cannot be expressed through the trait interface.

§Returns
  • A mutable reference to the underlying stack

Provided Methods§

Source

fn size(&self) -> usize

Gets the current size of the stack

This is a convenience method that delegates to len().

§Returns
  • The number of values currently on the stack

Implementors§