2 releases
0.1.1 | Dec 16, 2019 |
---|---|
0.1.0 | Dec 16, 2019 |
#41 in #guard
31 downloads per month
9KB
189 lines
💂♂️ Beefeater
Generic guard around any type that implements Copy.
Usage
Add a dependency to your Cargo.toml
:
[dependencies]
beefeater = "0.1"
Add a use declaration to import the crate:
use beefeater::Beefeater;
Finally, use the 💂♂️ Beefeater to guard access:
#[derive(Clone, Copy)]
enum State {
Playing,
Stopped,
}
fn main() {
let state = Arc::new(Beefeater::new(State::Playing));
{
let state = state.clone();
ctrlc::set_handler(move || {
println!("Recevied SIGINT, stopping playback");
state.store(State::Stopped);
}).unwrap();
}
loop {
match state.load() {
State::Playing => {
// Feed next chunk
}
State::Stopped => {
break;
}
}
}
}
lib.rs
:
Generic guard around any type that implements Copy