Crates.io | blackboard |
lib.rs | blackboard |
version | 1.1.0 |
source | src |
created_at | 2020-12-05 19:40:16.659274 |
updated_at | 2020-12-06 19:56:22.383526 |
description | A simple blackboard design pattern implementation in rust |
homepage | |
repository | https://github.com/mocomaminecraft/blackboard |
max_upload_size | |
id | 319919 |
size | 9,139 |
This crate includes a class to use a blackboard pattern in rust.
This pattern consists of a blackboard object, that has sections. Programs can get the content of a section,
put content on a section, or subscribe to be notified when a section changes.
use blackboard::BlackBoard;
fn main() {
let mut milk_acquired = 0;
let mut found_betsie = false;
{ //Must have this block because rust and lifetimes
let mut barn_blackboard = BlackBoard::new();
barn_blackboard.subscribe("Cows", |_| { milk_acquired += 1 });
barn_blackboard.subscribe("Chickens",
|c| {
if *c == "Betsie" { found_betsie = true; }
}
);
barn_blackboard.post("Cows", "Anna");
barn_blackboard.post("Cows", "Clara");
barn_blackboard.post("Chickens", "Gregory");
barn_blackboard.post("Sheep", "Daisy");
barn_blackboard.post("Sheep", "Rosie");
barn_blackboard.post("Cows", "Sugar");
barn_blackboard.post("Chickens", "Betsie");
barn_blackboard.post("Cows", "Anna");
}
assert_eq!(4, milk_acquired);
assert!(found_betsie);
}