Crates.io | sequencer |
lib.rs | sequencer |
version | 0.7.0 |
source | src |
created_at | 2022-02-25 01:33:10.169146 |
updated_at | 2022-03-28 15:24:10.049421 |
description | Dependency graph processing libarary |
homepage | |
repository | https://github.com/mdenchev/sequencer/ |
max_upload_size | |
id | 539158 |
size | 24,018 |
A way to create a dependency graph of items to be executed.
This crate allows you to create a Directed Acyclic Graph of items and track which items are currently "active". Once an item is marked as completed, any child nodes of that item that have all their parents completed are marked as active.
This crate was made for sequencing/scripting events for a game though it could be used for anything that can be modeled as a dependency graph.
Add the following to Cargo.toml:
sequencer = "0.1"
A simple linear sequence such as wait for 5 ticks and then print something can be expressed as:
enum Actions {
Wait(usize)
Print(String)
}
impl Actions {
fn tick(&mut self) -> bool {
match self {
...
}
}
}
fn main() {
let mut sequencer = Sequencer::default();
sequencer.new_seq(vec![Wait(5usize), Print("Done waiting".to_string())]);
while sequencer.is_active() {
// Activate next nodes ready for processing
sequencer.drain_queue(|_key, action| {});
// Process active nodes. Returning true means the node was finishes.
sequencer.for_each_active(|_key, item| item.tick());
}
}
Check examples dir for complete examples.