Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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