Skip to main content

object_rainbow/
assert_impl.rs

1#[macro_export]
2#[doc(hidden)]
3macro_rules! unpack_where {
4    ({$($a:tt)*} {$($tr:tt)*} {$ty:ty} {$($w:tt)*} {}) => {
5        const _: () = {
6            fn _inner<$($a)* X: $($tr)*>() $($w)* {}
7            fn _outer<$($a)*>() $($w)* {
8                _inner::<$($a)* $ty>()
9            }
10        };
11    };
12    ({$($a:tt)*} {$($tr:tt)*} {$ty:ty} {$($w:tt)*} $ww:tt $($www:tt)*) => {
13        $crate::unpack_where!{ {$($a)*} {$($tr)*} {$ty} {$($w)* $ww} $($www)* }
14    };
15}
16
17/// Assert that some `trait` is `impl`emented.
18///
19/// ```rust
20/// object_rainbow::assert_impl!(
21///     impl<T> Send for std::sync::Arc<T>
22///     where
23///         T: Send + Sync,
24///     {}
25/// );
26/// object_rainbow::assert_impl!(
27///     impl<T> Sync for std::sync::Arc<T>
28///     where
29///         T: Send + Sync,
30///     {}
31/// );
32/// ```
33#[macro_export]
34macro_rules! assert_impl {
35    (impl $(<$($a:ident),*>)? $tr:ident$(<$($tra:ident),*>)? for $ty:ty where $($w:tt)*) => {
36        $crate::unpack_where! { {$($($a,)*)?} {$tr$(<$($tra),*>)?} {$ty} {} where $($w)* }
37    };
38    (impl $(<$($a:ident),*>)? $tr:ident$(<$($tra:ident),*>)? for $ty:ty {}) => {
39        $crate::unpack_where! { {$($($a,)*)?} {$tr$(<$($tra),*>)?} {$ty} {} {} }
40    };
41}
42
43assert_impl!(
44    impl<T> Clone for T where T: Copy {}
45);
46
47assert_impl!(
48    impl Copy for i64 {}
49);