fitzgen / state_machine_future

Easily create type-safe `Future`s from state machines — without the boilerplate.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

the example doesn't build

bbigras opened this issue · comments

The example on the README is not complete. It could be useful to have a buildable one so people can try it faster.

And maybe provide a simpler example like:

extern crate futures;

#[macro_use]
extern crate state_machine_future;

use futures::{Future, Poll};
use state_machine_future::RentToOwn;

#[derive(Debug)]
struct MyItem {
    value: usize,
}

#[derive(Debug)]
struct MyError;

#[derive(StateMachineFuture)]
enum Foo {
    #[state_machine_future(start, transitions(Intermediate))]
    Start,

    #[state_machine_future(transitions(Intermediate, Ready))]
    Intermediate(()),

    #[state_machine_future(ready)]
    Ready(MyItem),

    #[state_machine_future(error)]
    Error(MyError),
}

impl PollFoo for Foo {
    fn poll_start<'a>(_start: &'a mut RentToOwn<'a, Start>) -> Poll<AfterStart, MyError> {
        println!("poll_start");
        transition!(Intermediate(()))
    }

    fn poll_intermediate<'a>(
        _intermediate: &'a mut RentToOwn<'a, Intermediate>,
    ) -> Poll<AfterIntermediate, MyError> {
        println!("poll_intermediate");
        transition!(Ready(MyItem { value: 5 }))
    }
}

fn main() {
    let r = Foo::start().wait().unwrap();
    println!("got: {:?}", r);
}

suggest create a example folder, and put runable example code in it.