3 releases
0.0.3 | Oct 25, 2024 |
---|---|
0.0.2 | Oct 15, 2024 |
0.0.1 | Oct 15, 2024 |
#766 in Algorithms
56 downloads per month
Used in 11 crates
(6 directly)
11KB
170 lines
🏃♂️ tick-queue
tick-queue
is a Rust library designed to manage a sequence of items in a strick tick order.
Each item is associated with a unique TickId
, ensuring items are kept in a correct order.
✨ Features
- Step Management: Queue items with associated
TickId
to ensure correct processing. - Iterator Support: Iterate through items with both standard and indexed iteration.
- Flexible Item Handling: Push, pop, and take items from the queue with tick validation.
- Error Handling: Robust error handling for cases such as incorrect
TickId
order.
🚀 Getting Started
Add tick-queue
to your Cargo.toml
:
[dependencies]
tick-queue = "0.0.3"
lib.rs
:
Tick Queue Crate
The tick-queue
crate provides utilities for managing a sequence of items.
Each item is associated with a unique tick identifier (TickId
), ensuring that items are processed in the correct order.
The crate offers functionality for pushing items, iterating over them, and managing the internal state of the item queue. It supports both direct manipulation of the item queue and indexed iteration.
Example
use tick_queue::{Queue, ItemInfo};
use tick_id::TickId;
// Create a new Queue instance with an initial tick
let mut queue = Queue::new(TickId::new(0));
// Push items into the queue
queue.push(TickId::new(0), "Step 1").unwrap();
queue.push(TickId::new(1), "Step 2").unwrap();
// Pop the first item
let item = queue.pop();
assert_eq!(item.unwrap().item, "Step 1");
// Iterate over remaining items
for item in queue.iter() {
println!("Tick {}: {}", item.tick_id, item.item);
}
Dependencies
~6KB