I am going to use state machine to handle the parser of SQL.
Working hard to find the better crate .
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);
}