astack 0.3.5

astack offers a Stack data structure with fixed capacity capable of fast LIFO operations.
Documentation
  • Coverage
  • 100%
    51 out of 51 items documented48 out of 49 items with examples
  • Size
  • Source code size: 90.91 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 3.36 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Links
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • lowfrank

astack.rs

astack offers a Stack data structure with fixed capacity capable of fast LIFO operations.

The crate is available in both std and non-std environments. It does not even require the alloc crate.

A Stack does not allow for indexing operations, but offers three ways to operate with the top of the stack:

  • Checked methods, such as pop and push: perform the operation and return an Option/Result if it does not succeed.
  • Panicking methods, such as pop_panicking and push_panicking: perform the operation and panic if it does not succeed.
  • Unchecked methods, such as pop_unchecked and push_unchecked: perform the operation but cause undefined behavior if it does not succeed.

Examples

use astack::stack;

fn main() {
    // Create an empty stack of i32 with can hold up to 8 numbers.
    let mut stack = stack![i32; 8];

    // Push an item to the end of the stack.
    // Returns Err if the stack is full.
    stack.push(10).unwrap();
    stack.push(20).unwrap();

    // Pop the top of the stack. Returns None if the stack is empty.
    assert_eq!(stack.pop(), Some(20));

    // Get a reference to TOS with Stack::tos.
    // Get a mutable reference to TOS with Stack::tos_mut.
    assert_eq!(stack.tos(), Some(&10));

    // Remove all the elements from the stack
    stack.clear();
    assert!(stack.is_empty());
}

License

Licensed under MIT license or Apache Licence 2.0