Last active
July 4, 2023 03:58
-
-
Save sam0x17/a1aa373a658c73d20d8c4a39e69da3bc to your computer and use it in GitHub Desktop.
rust assert_impl!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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