Stack

Trait Stack 

Source
pub trait Stack: Debug {
    type Error: Sized + Copy + Debug;

    // Required methods
    fn empty() -> Self;
    fn depth(&self) -> usize;
    fn peek(&self) -> Option<State>;
    fn pop(&mut self) -> Option<State>;
    fn push(&mut self, item: State) -> Result<(), Self::Error>;
}
Expand description

A trait representing a stack.

Required Associated Types§

Source

type Error: Sized + Copy + Debug

This stack’s error type.

Required Methods§

Source

fn empty() -> Self

Create an empty stack.

Source

fn depth(&self) -> usize

The current stack depth.

Source

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

Peek at the current item on the stack.

Source

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

Pop the next item from the stack.

Source

fn push(&mut self, item: State) -> Result<(), Self::Error>

Push an item onto the stack.

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.

Implementations on Foreign Types§

Source§

impl Stack for Vec<State>

Available on crate feature alloc only.

An unbounded Stack premised on the allocating Vec.

This SHOULD NOT be used. This allows serializations to use an unbounded amount of memory to represent objects of arbitrary depth. It’s here solely to offer ‘complete’ support for all possible serializations (compliant with RFC 8259).

Source§

type Error = Infallible

Source§

fn empty() -> Self

Source§

fn depth(&self) -> usize

Source§

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

Source§

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

Source§

fn push(&mut self, item: State) -> Result<(), Self::Error>

Implementors§

Source§

impl<const ONE_FOURTH_OF_MAX_DEPTH: usize> Stack for ConstStack<ONE_FOURTH_OF_MAX_DEPTH>

Source§

type Error = StackError