rune/
internal_macros.rs

1/// Helper to borrow out a [ResolveContext][crate::parse::ResolveContext].
2macro_rules! resolve_context {
3    ($q:expr) => {
4        $crate::parse::ResolveContext {
5            sources: $q.sources,
6            storage: $q.storage,
7        }
8    };
9}
10
11/// Call the given macro with repeated type arguments and counts.
12macro_rules! repeat_macro {
13    ($macro:ident) => {
14        $macro!(0);
15        $macro!(1, A a 0);
16        $macro!(2, A a 0, B b 1);
17        $macro!(3, A a 0, B b 1, C c 2);
18        $macro!(4, A a 0, B b 1, C c 2, D d 3);
19        #[cfg(not(test))]
20        $macro!(5, A a 0, B b 1, C c 2, D d 3, E e 4);
21        #[cfg(not(test))]
22        $macro!(6, A a 0, B b 1, C c 2, D d 3, E e 4, F f 5);
23        #[cfg(not(test))]
24        $macro!(7, A a 0, B b 1, C c 2, D d 3, E e 4, F f 5, G g 6);
25        #[cfg(not(test))]
26        $macro!(8, A a 0, B b 1, C c 2, D d 3, E e 4, F f 5, G g 6, H h 7);
27        #[cfg(not(test))]
28        $macro!(9, A a 0, B b 1, C c 2, D d 3, E e 4, F f 5, G g 6, H h 7, I i 8);
29        #[cfg(not(test))]
30        $macro!(10, A a 0, B b 1, C c 2, D d 3, E e 4, F f 5, G g 6, H h 7, I i 8, J j 9);
31        #[cfg(not(test))]
32        $macro!(11, A a 0, B b 1, C c 2, D d 3, E e 4, F f 5, G g 6, H h 7, I i 8, J j 9, K k 10);
33        #[cfg(not(test))]
34        $macro!(12, A a 0, B b 1, C c 2, D d 3, E e 4, F f 5, G g 6, H h 7, I i 8, J j 9, K k 10, L l 11);
35        #[cfg(not(test))]
36        $macro!(13, A a 0, B b 1, C c 2, D d 3, E e 4, F f 5, G g 6, H h 7, I i 8, J j 9, K k 10, L l 11, M m 12);
37        #[cfg(not(test))]
38        $macro!(14, A a 0, B b 1, C c 2, D d 3, E e 4, F f 5, G g 6, H h 7, I i 8, J j 9, K k 10, L l 11, M m 12, N n 13);
39        #[cfg(not(test))]
40        $macro!(15, A a 0, B b 1, C c 2, D d 3, E e 4, F f 5, G g 6, H h 7, I i 8, J j 9, K k 10, L l 11, M m 12, N n 13, O o 14);
41        #[cfg(not(test))]
42        $macro!(16, A a 0, B b 1, C c 2, D d 3, E e 4, F f 5, G g 6, H h 7, I i 8, J j 9, K k 10, L l 11, M m 12, N n 13, O o 14, P p 15);
43    };
44}
45
46macro_rules! cfg_std {
47    ($($item:item)*) => {
48        $(
49            #[cfg(feature = "std")]
50            #[cfg_attr(rune_docsrs, doc(cfg(feature = "std")))]
51            $item
52        )*
53    }
54}
55
56macro_rules! assert_impl {
57    ($ty:ty: $first_trait:ident $(+ $rest_trait:ident)*) => {
58        #[cfg(test)]
59        const _: () = const {
60            const fn assert_traits<T>() where T: $first_trait $(+ $rest_trait)* {}
61            assert_traits::<$ty>();
62        };
63    };
64}