Skip to content

Instantly share code, notes, and snippets.

@sam0x17
Last active July 4, 2023 03:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sam0x17/a1aa373a658c73d20d8c4a39e69da3bc to your computer and use it in GitHub Desktop.
Save sam0x17/a1aa373a658c73d20d8c4a39e69da3bc to your computer and use it in GitHub Desktop.
rust assert_impl!
macro_rules! assert_impl {
($typ:ty, $($trait:path),*$(,)?) => {
{
const fn _assert_impl<T>()
where
T: $($trait +)* ?Sized,
{}
_assert_impl::<$typ>();
}
}
}
macro_rules! assert_impl_all {
($($typ:ty),* : $($tt:tt)*) => {{
const fn _assert_impl<T>() where T: $($tt)*, {}
$(_assert_impl::<$typ>();)*
}};
}
#[derive(Copy, Clone, Eq, PartialEq)]
struct MyStruct;
assert_impl!(MyStruct, Copy, Clone, Eq, PartialEq);
assert_impl_all!(u8, i32, bool, isize : Clone + Eq + PartialEq);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment