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
impl Stack
Sourcepub fn total_space(&self) -> usize
pub fn total_space(&self) -> usize
Returns the capacity of the stack (how big it is) in bytes.
Sourcepub fn used_space(&self) -> usize
pub fn used_space(&self) -> usize
Returns how much space of the stack has been used in bytes.
Sourcepub fn space_left(&self) -> usize
pub fn space_left(&self) -> usize
Returns how much space is left of the stack in bytes.
Sourcepub unsafe fn set_used_space(&mut self, new_len: usize)
pub unsafe fn set_used_space(&mut self, new_len: usize)
Sourcepub fn push_byte(&mut self, byte: u8) -> Result<(), StackOverflow>
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
).
Sourcepub fn push_bytes(&mut self, bytes: &[u8]) -> Result<(), StackOverflow>
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.
Sourcepub fn alloc(&mut self, bytes: usize) -> Result<(), StackOverflow>
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
).
Sourcepub unsafe fn dealloc(&mut self, bytes: usize) -> Result<(), StackOverflow>
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.
Sourcepub fn pop_u16(&mut self) -> Option<u16>
pub fn pop_u16(&mut self) -> Option<u16>
Pops a 16-bit big endian unsigned integer from the stack.