Last active
August 29, 2015 14:19
-
-
Save paulosuzart/d2191770999c000401ba to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
macro_rules! decl { | |
($i:ident: $t:ident, {$($name:ident: $ft:ty),+}, {$($on:ident: $ot:ty),*}) => { | |
mod $i { | |
use core::ql2::Term_TermType; | |
use rustc_serialize::json::Json; | |
use rustc_serialize::json; | |
use core::select::Table; | |
pub struct Opts { | |
$($on: Option<$ot>)* | |
} | |
impl Opts { | |
pub fn new() -> Opts { | |
Opts { | |
$($on : None)* | |
} | |
} | |
$( | |
pub fn $on (&mut self, v : $ot) -> &mut Opts { | |
self.$on = Some(v); | |
self | |
} | |
)* | |
} | |
pub struct Args<'a> { | |
term : Term_TermType, | |
stm : String, | |
table : &'a Table<'a>, | |
opts : Opts, | |
$($name : $ft),* | |
} | |
impl<'a> Args<'a> { | |
pub fn new(table : &'a Table, $($name : $ft),*) -> Args<'a> { | |
Args { | |
term : Term_TermType::$t, | |
stm : stringify!($i).to_string(), | |
table : table, | |
opts : Opts::new(), | |
$($name : $name),* | |
} | |
} | |
} | |
} | |
} | |
} | |
mod usage { | |
decl!{ | |
between: BETWEEN, { | |
min : json::Json, | |
max : json::Json | |
}, { | |
index : String | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment