iT邦幫忙

2019 iT 邦幫忙鐵人賽

DAY 26
1

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

上一篇
StellarSQL 24: Different Client Design of DBMS
下一篇
26: Grammer `Create`
系列文
Let's build a DBMS: StellarSQL -- a minimal SQL DBMS written in Rust30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言