Typestate
Example Implementations
Rust
struct State { /* data here */}
struct TopLevelObject<S: TypeState> {
state: Box<State>
marker: PhantomData<S>
}
enum State1 {}
enum State2 {}
trait TypeState {}
impl TypeState for State1 { }
impl TyepState for State2 { }
impl TopLevelObject<State1> {
fn new() -> Self { todo!() }
fn next() -> TopLevelObject<State2> { todo!() }
}
- http://cliffle.com/blog/rust-typestate/
- https://hoverbear.org/blog/rust-state-machine-pattern/#structures-with-transitions
Typescript
interface State1 { }
interface State2 { }