Trait StackTr

pub trait StackTr {
    // Required methods
    fn len(&self) -> usize;
    fn push(&mut self, value: Uint<256, 4>) -> bool;
    fn popn<const N: usize>(&mut self) -> Option<[Uint<256, 4>; N]>;
    fn popn_top<const POPN: usize>(
        &mut self,
    ) -> Option<([Uint<256, 4>; POPN], &mut Uint<256, 4>)>;
    fn exchange(&mut self, n: usize, m: usize) -> bool;
    fn dup(&mut self, n: usize) -> bool;

    // Provided methods
    fn is_empty(&self) -> bool { ... }
    fn push_b256(&mut self, value: FixedBytes<32>) -> bool { ... }
    fn top(&mut self) -> Option<&mut Uint<256, 4>> { ... }
    fn pop(&mut self) -> Option<Uint<256, 4>> { ... }
    fn pop_address(&mut self) -> Option<Address> { ... }
}
Expand description

Functions needed for Interpreter Stack operations.

Required Methods§

fn len(&self) -> usize

Returns stack length.

fn push(&mut self, value: Uint<256, 4>) -> bool

Pushes values to the stack.

Returns true if push was successful, false if stack overflow.

§Note

Error is internally set in interpreter.

fn popn<const N: usize>(&mut self) -> Option<[Uint<256, 4>; N]>

Pops value from the stack.

fn popn_top<const POPN: usize>( &mut self, ) -> Option<([Uint<256, 4>; POPN], &mut Uint<256, 4>)>

Pop N values from the stack and return top value.

fn exchange(&mut self, n: usize, m: usize) -> bool

Exchanges two values on the stack.

Indexes are based from the top of the stack.

Returns true if swap was successful, false if stack underflow.

fn dup(&mut self, n: usize) -> bool

Duplicates the Nth value from the top of the stack.

Index is based from the top of the stack.

Returns true if duplicate was successful, false if stack underflow.

Provided Methods§

fn is_empty(&self) -> bool

Returns true if stack is empty.

fn push_b256(&mut self, value: FixedBytes<32>) -> bool

Pushes B256 value to the stack.

Internally converts B256 to U256 and then calls StackTr::push.

fn top(&mut self) -> Option<&mut Uint<256, 4>>

Returns top value from the stack.

fn pop(&mut self) -> Option<Uint<256, 4>>

Pops one value from the stack.

fn pop_address(&mut self) -> Option<Address>

Pops address from the stack.

Internally call StackTr::pop and converts U256 into Address.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

§

impl StackTr for Stack