Skip to content

Instantly share code, notes, and snippets.

View Aatch's full-sized avatar

James Miller Aatch

View GitHub Profile
@Aatch
Aatch / one_shot.rs
Last active December 16, 2015 11:38
struct OneShot<S, T> (S, ~fn (S) -> T);
impl<S, T> OneShot<S,T> {
fn run(~self) -> T {
let (s, f) = match self {
~OneShot(s, f) => (s,f)
};
f(s)
}
macro_rules! handle_element(
($tag:expr, $string:expr, $ctor:ident, [], $type_id:expr) => ( () );
($tag:expr, $string:expr, $ctor:ident, [ $($field:ident),* ], $type_id:expr, ) => (
if eq_slice($tag, $string) {
let _element = ~$ctor {
parent: Element::new($type_id, ($tag).to_str()),
$(
$field: None
),*
};