Skip to content

Instantly share code, notes, and snippets.

Created August 6, 2015 04:58
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/ecdba0ee7c1d4e42d720 to your computer and use it in GitHub Desktop.
Save anonymous/ecdba0ee7c1d4e42d720 to your computer and use it in GitHub Desktop.
Shared via Rust Playground
macro_rules! as_item {
($i:item) => {$i};
}
macro_rules! impl_partial_eq {
([$($lt:tt)*] $lhs:ty, $rhs:ty) => {
as_item! {
impl<$($lt)*> PartialEq<$rhs> for $lhs {
fn eq(&self, other: &$rhs) -> bool {
// common implementation of PartialEq goes here
panic!()
}
}
}
};
}
struct Foo<'a> { x: &'a i32 }
impl_partial_eq!(['a] Foo<'a>, Foo<'a>);
fn main() {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment