Trait stack_trait::Stack

source ·
pub trait Stack {
    type Item;

    // Required methods
    fn s_is_empty(&self) -> bool;
    fn s_push(&mut self, item: Self::Item);
    fn lifo_push(&mut self, item: Self::Item) -> LIFOEntry<'_, Self>;
    fn s_pop(&mut self) -> Option<Self::Item>;
    fn lifo_ref(&self) -> Option<&Self::Item>;
    fn lifo_mut(&mut self) -> Option<&mut Self::Item>;

    // Provided methods
    fn s_push_checked(&mut self, item: Self::Item) -> Option<()> { ... }
    unsafe fn s_pop_unchecked(&mut self) -> Self::Item { ... }
    fn lifo(&mut self) -> Option<LIFOEntry<'_, Self>> { ... }
    unsafe fn lifo_unchecked(&mut self) -> LIFOEntry<'_, Self> { ... }
    unsafe fn lifo_ref_unchecked(&self) -> &Self::Item { ... }
    unsafe fn lifo_mut_unchecked(&mut self) -> &mut Self::Item { ... }
}
Expand description

Implementors of this method can be used as a stack in DSA terms.

Required Associated Types§

source

type Item

The type of the items stored in the stack.

Required Methods§

source

fn s_is_empty(&self) -> bool

Returns true if the stack is empty.

source

fn s_push(&mut self, item: Self::Item)

Pushes an item to the stack.

For vector, use Vec::push instead.

Also see
source

fn lifo_push(&mut self, item: Self::Item) -> LIFOEntry<'_, Self>

Pushes an item to the stack and returns an the “entry” object corresponding to the pushed element.

source

fn s_pop(&mut self) -> Option<Self::Item>

Pops an item from the stack.

Notes

For vector, use Vec::pop instead.

Also see
source

fn lifo_ref(&self) -> Option<&Self::Item>

Returns a shared reference to the top element of the stack.

Also see
source

fn lifo_mut(&mut self) -> Option<&mut Self::Item>

Returns a mutable reference to the top element of the stack.

Also see

Provided Methods§

source

fn s_push_checked(&mut self, item: Self::Item) -> Option<()>

Pushes an item to the stack.

Notes

For vector, use Vec::push instead. It is meant primarily for the heapless::Vec.

Also see
source

unsafe fn s_pop_unchecked(&mut self) -> Self::Item

Pops an item from the stack without checking if the stack is empty.

Safety

The stack must not be empty.

Also see
source

fn lifo(&mut self) -> Option<LIFOEntry<'_, Self>>

Returns an “entry” object corresponding to the top element of the stack.

Notes

This is useful when the entry might need to be used to be dereferenced to &T and/or &mut T and/or be promoted to T by popping the item from the stack.

Also see
source

unsafe fn lifo_unchecked(&mut self) -> LIFOEntry<'_, Self>

Returns an “entry” object corresponding to the top element of the stack without checking if the stack is empty.

Safety

The stack must not be empty.

Also see
source

unsafe fn lifo_ref_unchecked(&self) -> &Self::Item

Returns a shared reference to the top element of the stack without checking if the stack is empty.

Safety

The stack must not be empty.

Also see
source

unsafe fn lifo_mut_unchecked(&mut self) -> &mut Self::Item

Returns a mutable reference to the top element of the stack without checking if the stack is empty.

Safety

The stack must not be empty.

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl<T> Stack for Vec<T>

§

type Item = T

source§

fn s_is_empty(&self) -> bool

source§

fn s_push(&mut self, item: Self::Item)

source§

fn lifo_push(&mut self, item: Self::Item) -> LIFOEntry<'_, Self>

source§

fn s_pop(&mut self) -> Option<Self::Item>

source§

fn lifo_ref(&self) -> Option<&Self::Item>

source§

fn lifo_mut(&mut self) -> Option<&mut Self::Item>

Implementors§