Crates.io | taker |
lib.rs | taker |
version | 0.1.0 |
source | src |
created_at | 2021-03-23 18:04:29.681687 |
updated_at | 2021-03-23 18:04:29.681687 |
description | Option-like taking for everyting with a default value. |
homepage | |
repository | https://github.com/DenisKolodin/taker |
max_upload_size | |
id | 372666 |
size | 2,878 |
Make FSM on any that that has Default
implementation.
How to use it:
#[derive(Debug, PartialEq, Eq)]
enum Fsm {
State1,
State2,
Transition,
}
impl Default for Fsm {
fn default() -> Self {
Self::Transition
}
}
let mut fsm = Fsm::State1;
match fsm.take() {
Fsm::State1 => {
fsm.set(Fsm::State2);
}
Fsm::State2 => {
fsm.set(Fsm::State1);
}
_ => {
panic!("Stucked in transition state...");
}
}