Struct microstack::Stack

source ·
pub struct Stack<V, const N: usize> { /* private fields */ }
Expand description

This is a simplest and the fastest implementation of a stack on stack.

For example, here is how a stack can be created:

use microstack::Stack;
let mut s : Stack<u64, 10> = Stack::new();
s.push(1);
s.push(2);
assert_eq!(2, *s.pop().unwrap());

Implementations§

source§

impl<V, const N: usize> Stack<V, N>

source

pub const fn new() -> Self

Make it.

The size of the stack is defined by the generic argument.

source§

impl<V, const N: usize> Stack<V, N>

source

pub fn from_vec(v: Vec<V>) -> Self

Make it from vector.

source

pub fn capacity(&mut self) -> usize

Get the capacity.

source

pub fn push(&mut self, v: V)

Push new element into it.

source

pub fn pop(&mut self) -> Option<&V>

Pop a element from it.

source

pub fn clear(&mut self)

Clear.

source

pub const fn is_empty(&self) -> bool

Is it empty.

source

pub const fn len(&self) -> usize

Length of it.

source

pub fn iter(&self) -> impl Iterator<Item = &V>

Iterate them.

source§

impl<'a, V: Clone + 'a, const N: usize> Stack<V, N>

source

pub fn into_iter(&self) -> impl Iterator<Item = V> + '_

Into-iterate them.

Trait Implementations§

source§

impl<V: Clone, const N: usize> Clone for Stack<V, N>

source§

fn clone(&self) -> Self

Clone it.

1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<V: Display, const N: usize> Debug for Stack<V, N>

source§

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

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

impl<V, const N: usize> Default for Stack<V, N>

source§

fn default() -> Self

Make a default empty Stack.

source§

impl<V: Display, const N: usize> Display for Stack<V, N>

source§

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

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

impl<V, const N: usize> Drop for Stack<V, N>

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<V, const N: usize> RefUnwindSafe for Stack<V, N>where V: RefUnwindSafe,

§

impl<V, const N: usize> Send for Stack<V, N>where V: Send,

§

impl<V, const N: usize> Sync for Stack<V, N>where V: Sync,

§

impl<V, const N: usize> Unpin for Stack<V, N>where V: Unpin,

§

impl<V, const N: usize> UnwindSafe for Stack<V, N>where V: UnwindSafe,

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

source§

fn into(self) -> U

Calls U::from(self).

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

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for Twhere T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

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

§

type Error = Infallible

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

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

Performs the conversion.
source§

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

§

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

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

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

Performs the conversion.