Skip to main content

Stack

Trait Stack 

Source
pub trait Stack {
    // Required methods
    fn push(&mut self) -> Result<()>;
    fn pop_n(&mut self, n: usize) -> Result<()>;

    // Provided method
    fn pop(&mut self) -> Result<()> { ... }
}
Expand description

Trait to model entities that can push and pop their state on a stack structure.

Many components in formally allow to push and pop their state as a stack structure, most prominently SMT solvers from the smt crate. This trait abstracts this capability.

Since the logic to support these operations can sometimes be factored out, we also provide the Stacked type to help implementing Stack on your own data structure.

Implementors should note that popping out a number of frames equal or larger than the number of frames pushed should, by convention, result into an object equivalent to its Default value.

Required Methods§

Source

fn push(&mut self) -> Result<()>

Push the current state of the object to the stack.

Source

fn pop_n(&mut self, n: usize) -> Result<()>

Pop n frames from the stack, restoring the state of the nth topmost frame.

It is allowed to provide a value of n larger than the number of frames.

Provided Methods§

Source

fn pop(&mut self) -> Result<()>

Shortcut for pop_n(1)

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<T: Clone + Default> Stack for Stacked<T>

Source§

impl<T: Hash + Eq> Stack for Scope<T>