Skip to content

Instantly share code, notes, and snippets.

Created June 25, 2015 20:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/a96b9840c7034540e085 to your computer and use it in GitHub Desktop.
Save anonymous/a96b9840c7034540e085 to your computer and use it in GitHub Desktop.
Shared via Rust Playground
#![allow(dead_code)]
macro_rules! as_item { ($i:item) => ($i) }
macro_rules! s {
($t:ident) => {
impl $t {
}
};
($t:ident<$($x:tt),+>) => {
as_item!(
impl <$($x),+> $t <$($x),+> {
}
);
}
}
#[derive(Debug)] struct Thing { i: i32 }
#[derive(Debug)] struct OtherThing<'a, 'b, T> { p1: &'a i32, p2: &'b i32, t: T }
s!(Thing);
s!(OtherThing<'a, 'b, T>);
fn main() {
let a = Thing { i: 42 };
let b = OtherThing { p1: &a.i, p2: &42, t: "moo" };
println!("{:?} {:?}", a, b);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment