In learning Rust, I try to implement a simple, clean FSM, very similar to this example that I used many times in Go:
package main import ( "fmt" ) type StateFn func(interface{}) StateFn func First(interface{}) StateFn { fmt.Println("First") return Second } func Second(interface{}) StateFn { fmt.Println("Second") return nil } func main() { for state := First(nil); state != nil; state = state(nil) {} }
I hope for something similar pure and expressive and, ideally, general, so I do not need to use the Rust interface{} equivalent in the func parameter.
This question is an extension. How to determine the type of a Rust function that returns its own type? .
burfl source share