Skip to content

therustmonk/taker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

taker

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...");
    }
}

About

Option-like taking for everything (Rust)

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages