astack-0.1.0 has been yanked.
astack
offers a [Stack
] data structure with fixed capacity aimed at
fast LIFO operations.
The crate contains:
- A [
Stack
] struct, the object used to perform stack operations such as [push
][Stack::push] and [pop
][Stack::pop]. - A [
stack
] macro, used to conveniently construct a new [Stack
]. - A [
StackOverflowError
], emitted by [Stack
] if an operation would have resulted in a stack overflow.
astack
may be used in both std and non-std environments, and is therefore
considered platform-agnostic.
Examples
Creating an empty Stack
.
use ;
// Through the Stack::new() method
let stack = new;
// Through the stack! macro
let stack = stack!;
Creating a Stack
with already some items inside.
use stack;
// Through the stack! macro
let stack = stack! ;
Creating a Stack
filled with items.
use Stack;
// A Stack filled with one single Copy item.
let stack_of_44 = fill_with_copy;
// A Stack filled with the Default implementation of `T`.
let stack_of_default = fill_with_default;
// A Stack filled with a value based on the result of a function.
let stack = fill_with_fn;
Common Stack
operations
use astack::stack;
// Create a new Stack.
let mut stack = stack! {
[i32; 4] = [10, 20, 30]
};
// Add an item as TOS. This returns Err if the stack if full.
stack.push(40).unwrap();
// Pop TOS. This returns None if the stack is empty.
let last_value = stack.pop().unwrap();
// Get a reference to TOS. This returns None if the stack is empty.
let top_of_the_stack = stack.tos().unwrap();
// Get a mutable reference to TOS. This returns None if the stack is empty.
let top_of_the_stack_mut = stack.tos_mut().unwrap();