Stack

Struct Stack 

Source
pub struct Stack<T> {
    pub head: Option<Box<StackNode<T>>>,
    pub length: u16,
}

Fields§

§head: Option<Box<StackNode<T>>>§length: u16

Implementations§

Source§

impl<T: Clone> Stack<T>

Source

pub fn new() -> Self

Source

pub fn pop(&mut self) -> Result<(usize, T), StackError>

Source

pub fn push(&mut self, item: T) -> Result<usize, StackError>
where T: Clone,

Source

pub fn dup(&mut self, index: usize) -> Result<(usize, T), StackError>

Source

pub unsafe fn swap( &mut self, index: usize, ) -> Result<([usize; 2], [T; 2]), StackError>

Documentation

§Safety

As Stack::swap, it swaps a specific item with the head of stack.

Source

pub fn is_empty(&self) -> bool

Source

pub fn peek(&self) -> Option<&T>

Trait Implementations§

Source§

impl<T: Debug> Debug for Stack<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T> Default for Stack<T>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<T> Freeze for Stack<T>

§

impl<T> RefUnwindSafe for Stack<T>
where T: RefUnwindSafe,

§

impl<T> Send for Stack<T>
where T: Send,

§

impl<T> Sync for Stack<T>
where T: Sync,

§

impl<T> Unpin for Stack<T>

§

impl<T> UnwindSafe for Stack<T>
where T: UnwindSafe,

Blanket Implementations§

§

impl<T> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Into<U> for T
where U: From<T>,

§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.