Struct Stack

Source
pub struct Stack {
    pub vec: Vec<u8>,
}
Expand description

A stack.

A stack is a kind of memory that can only be manipulated by pushing (appending) an element, or by popping (removing) the last element, like a stack of plates, which makes it a **first in, last out (LOFI) ** data type.

Fields§

§vec: Vec<u8>

The data storage of the stack.

Implementations§

Source§

impl Stack

Source

pub fn total_space(&self) -> usize

Returns the capacity of the stack (how big it is) in bytes.

Source

pub fn used_space(&self) -> usize

Returns how much space of the stack has been used in bytes.

Source

pub fn space_left(&self) -> usize

Returns how much space is left of the stack in bytes.

Source

pub unsafe fn set_used_space(&mut self, new_len: usize)

Sets how much space is used of the stack.

§Safety

Any value of type u8 can’t possibly be invalid.

The caller must guarantee that new_len doesn’t exceed the capacity of the stack.

Source

pub fn push_byte(&mut self, byte: u8) -> Result<(), StackOverflow>

Pushes a byte onto the Stack.

§Errors

Returns StackOverflow if the stack has no more space (capacity == length).

Source

pub fn pop_byte(&mut self) -> Option<u8>

Pops a byte from the Stack.

Returns None if there are no bytes on the Stack.

Source

pub fn push_bytes(&mut self, bytes: &[u8]) -> Result<(), StackOverflow>

Copies a slice onto the Stack.

This is done by allocating bytes bytes and writing the slice onto the buffer using ptr::copy

§Errors

Returns StackOverflow and doesn’t allocate if the stack doesn’t have enough space left.

Source

pub fn alloc(&mut self, bytes: usize) -> Result<(), StackOverflow>

Pushes bytes bytes onto the Stack.

§Errors

Returns StackOverflow and doesn’t allocate if the bytes don’t fit on the stack (bytes > capacity - length).

Source

pub unsafe fn dealloc(&mut self, bytes: usize) -> Result<(), StackOverflow>

Pops bytes bytes from the Stack.

Pops the amount of bytes specified and returns a slice of them.

§Errors

Returns StackOverflow if there is not enough space.

§Safety

The caller must guarantee that the slice isn’t used when the Stack is pushed onto again to prevent race conditions.

Source

pub fn pop_u16(&mut self) -> Option<u16>

Pops a 16-bit big endian unsigned integer from the stack.

Source

pub fn pop_u32(&mut self) -> Option<u32>

Pops a 32-bit big endian unsigned integer from the stack.

Source

pub fn pop_u64(&mut self) -> Option<u64>

Pops a 64-bit big endian unsigned integer from the stack.

Trait Implementations§

Source§

impl Clone for Stack

Source§

fn clone(&self) -> Stack

Returns a copy of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Stack

Source§

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

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

impl Default for Stack

Source§

fn default() -> Self

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

Auto Trait Implementations§

§

impl Freeze for Stack

§

impl RefUnwindSafe for Stack

§

impl Send for Stack

§

impl Sync for Stack

§

impl Unpin for Stack

§

impl UnwindSafe for Stack

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, 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.