iT邦幫忙

2019 iT 邦幫忙鐵人賽

DAY 27
1

working on it.

use futures::Async;
use futures::Future;
use futures::Poll;
use state_machine_future::RentToOwn;
use std::slice::Iter;
use sql::symbol::Symbol;
use component::database::Database;
use component::table::Table;


pub struct Context<T>
    where T: Table + Database
{
    iter: Iter<Symbol>,
    target: T,
}

impl<T> Context<T> {
    fn new(iter: Iter<Symbol>, target: T) -> Context {
        Context {
            iter,
            target,
        }
    }
}

pub enum GrammarError {
    NoIdentifier,

}

#[derive(StateMachineFuture)]
#[state_machine_future(context = "Context")]
pub enum SqlCreate<T> {
    #[state_machine_future(start, transitions(GetName))]
    Start,

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

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

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

impl<T> PollSqlCreate<T> for SqlCreate<T> {
    fn poll_start<'s, 'c>(
        _: &'s mut RentToOwn<'s, Start>,
        context: &'c mut RentToOwn<'c, Context<T>>,
    ) -> Poll<AfterStart<T>, Error> {
        transition!(GetName)
    }

    fn poll_get_name<'s, 'c>(
        _: &'s mut RentToOwn<'s, Start>,
        context: &'c mut RentToOwn<'c, Context<T>>,
    ) -> Poll<AfterGetName<T>, Error> {
        match context.iter.next() {
            Some(symbol) => {
                if
                context.target.name 
            }
            None => 
        }
        transition!(Ready)
    }
}



#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_create() {
        let r = CreateDatabase::start().wait().unwrap();
        println!("got: {:?}", r);
    }

}

上一篇
State Machine
下一篇
27: I/O handling
系列文
Let's build a DBMS: StellarSQL -- a minimal SQL DBMS written in Rust30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言