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