#stack #no-alloc #no-std #lifo

no-std astack

astack 提供了一个具有固定容量且能够快速执行 LIFO 操作的 Stack 数据结构

1 个不稳定版本

0.3.5 2024年4月29日
0.3.4 2024年4月29日
0.3.2 2023年9月27日
0.2.1 2023年9月18日
0.1.0 2023年9月17日

数据结构 中排名第 1764

Download history 406/week @ 2024-04-28 9/week @ 2024-05-05 4/week @ 2024-05-19 13/week @ 2024-06-30 15/week @ 2024-07-21 57/week @ 2024-07-28

每月下载量 72

MIT/Apache

76KB
725

astack.rs

astack 提供了一个具有固定容量且能够快速执行 LIFO 操作的 Stack 数据结构。

该包既适用于 std 环境也适用于非 std 环境。它甚至不需要 alloc 包。

Stack 不允许索引操作,但提供了三种与栈顶进行操作的方法

  • 检查方法,如 poppush:执行操作并返回一个 Option/Result 如果操作不成功。
  • 恐慌方法,如 pop_panickingpush_panicking:执行操作,如果操作不成功则引发恐慌。
  • 未检查方法,如 pop_uncheckedpush_unchecked:执行操作,如果操作不成功则引发未定义的行为。

示例

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

许可证

许可协议下 MIT 许可证Apache 许可证 2.0

无运行时依赖

功能