Struct Stack

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

This is a simplest and the fastest implementation of a stack on stack, when stack elements are Copy implementing primitives.

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());

Implementations§

Source§

impl<V: Copy, 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<'a, V: Copy + 'a, const N: usize> Stack<V, N>

Source

pub const fn into_iter(&self) -> IntoIter<V, N>

Into-iterate them.

Source§

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

Source

pub const fn iter(&self) -> Iter<'_, V, N>

Iterate them.

Source§

impl<V: Copy, 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 unsafe fn push_unchecked(&mut self, v: V)

Push new element into it.

§Safety

It may lead to undefined behavior, if you go over the boundary.

Source

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

Push new element into it.

§Panics

If there is no more space in the stack, it will panic.

Source

pub fn try_push(&mut self, v: V) -> Result<(), String>

Makes an attempt to push a new element into the stack.

If there was enough space in the stack, Ok(v) is returned, while Err is returned otherwise.

§Errors

If there is not enough space in the stack, Err is returned.

Source

pub unsafe fn pop_unchecked(&mut self) -> V

Pop a element from it.

§Safety

If there are no items in the array, the result is undefined.

Source

pub fn pop(&mut self) -> V

Pop a element from it.

§Panics

If there are no items in the array, it will panic.

Source

pub fn try_pop(&mut self) -> Result<V, String>

Pop a element from it.

§Errors

If there is no more elements left, it will return None.

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.

Trait Implementations§

Source§

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

Source§

fn clone(&self) -> Self

Clone it.

1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<V: Display + Copy, 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: Copy, const N: usize> Default for Stack<V, N>

Source§

fn default() -> Self

Make a default empty Stack.

Source§

impl<V: Display + Copy, 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

Auto Trait Implementations§

§

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

§

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 T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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 T
where 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 T
where T: Clone,

Source§

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 T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

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

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

Source§

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 T
where U: TryFrom<T>,

Source§

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.