• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /// Asserts that the trait is a child of all of the other traits.
2 ///
3 /// Related:
4 /// - [`assert_trait_super_all!`]
5 ///
6 /// # Examples
7 ///
8 /// All types that implement [`Copy`] must implement [`Clone`]:
9 ///
10 /// ```
11 /// # #[macro_use] extern crate static_assertions; fn main() {}
12 /// assert_trait_sub_all!(Copy: Clone);
13 /// ```
14 ///
15 /// All types that implement [`Ord`] must implement [`PartialEq`], [`Eq`], and
16 /// [`PartialOrd`]:
17 ///
18 /// ```
19 /// # #[macro_use] extern crate static_assertions; fn main() {}
20 /// assert_trait_sub_all!(Ord: PartialEq, Eq, PartialOrd);
21 /// ```
22 ///
23 /// The following example fails to compile because [`Eq`] is not required for
24 /// [`PartialOrd`]:
25 ///
26 /// ```compile_fail
27 /// # #[macro_use] extern crate static_assertions; fn main() {}
28 /// assert_trait_sub_all!(PartialOrd: Eq);
29 /// ```
30 ///
31 /// [`assert_trait_super_all!`]: macro.assert_trait_super_all.html
32 ///
33 /// [`Copy`]:       https://doc.rust-lang.org/std/marker/trait.Copy.html
34 /// [`Clone`]:      https://doc.rust-lang.org/std/clone/trait.Clone.html
35 /// [`Ord`]:        https://doc.rust-lang.org/std/cmp/trait.Ord.html
36 /// [`PartialOrd`]: https://doc.rust-lang.org/std/cmp/trait.PartialOrd.html
37 /// [`Eq`]:         https://doc.rust-lang.org/std/cmp/trait.Eq.html
38 /// [`PartialEq`]:  https://doc.rust-lang.org/std/cmp/trait.PartialEq.html
39 #[macro_export(local_inner_macros)]
40 macro_rules! assert_trait_sub_all {
41     ($sub:path: $($super:path),+ $(,)?) => {
42         assert_impl!(for(T: $sub) T: $( ($super) )&+);
43     };
44 }
45 
46 /// Asserts that the trait is a parent of all of the other traits.
47 ///
48 /// Related:
49 /// - [`assert_trait_sub_all!`]
50 ///
51 /// # Examples
52 ///
53 /// With this, traits `A` and `B` can both be tested to require [`Copy`] on a
54 /// single line:
55 ///
56 /// ```
57 /// # use static_assertions::assert_trait_super_all;
58 /// trait A: Copy {}
59 /// trait B: Copy {}
60 ///
61 /// assert_trait_super_all!(Copy: A, B);
62 /// ```
63 ///
64 /// Otherwise, each sub-trait would require its own call to
65 /// [`assert_trait_sub_all!`]:
66 ///
67 /// ```
68 /// # #[macro_use] extern crate static_assertions; fn main() {}
69 /// # trait A: Copy {}
70 /// # trait B: Copy {}
71 /// assert_trait_sub_all!(A: Copy);
72 /// assert_trait_sub_all!(B: Copy);
73 /// ```
74 ///
75 /// The following example fails to compile because trait `C` does not require
76 /// [`Copy`]:
77 ///
78 /// ```compile_fail
79 /// # use static_assertions::assert_trait_super_all;
80 /// # trait A: Copy {}
81 /// # trait B: Copy {}
82 /// trait C {}
83 ///
84 /// assert_trait_super_all!(Copy: A, B, C);
85 /// ```
86 ///
87 /// [`assert_trait_sub_all!`]: macro.assert_trait_sub_all.html
88 ///
89 /// [`Copy`]: https://doc.rust-lang.org/std/marker/trait.Copy.html
90 #[macro_export(local_inner_macros)]
91 macro_rules! assert_trait_super_all {
92     ($super:path: $($sub:path),+ $(,)?) => {
93         $(assert_trait_sub_all!($sub: $super);)+
94     };
95 }
96 
97 /// Asserts that the trait is a child of one or more of the other traits.
98 ///
99 /// Related:
100 /// - [`assert_impl_any!`]
101 ///
102 /// # Examples
103 ///
104 /// All types that implement [`Copy`] must implement [`Clone`]:
105 ///
106 /// ```
107 /// # #[macro_use] extern crate static_assertions; fn main() {}
108 /// assert_trait_sub_any!(Copy: Clone);
109 /// ```
110 ///
111 /// All types that implement [`Ord`] must implement [`Eq`], but don't have to implement [`Clone`]:
112 ///
113 /// ```
114 /// # #[macro_use] extern crate static_assertions; fn main() {}
115 /// assert_trait_sub_any!(Ord: Eq, Clone);
116 /// ```
117 ///
118 /// The following example fails to compile because neither [`Eq`] nor [`Clone`] are required for
119 /// [`PartialOrd`]:
120 ///
121 /// ```compile_fail
122 /// # #[macro_use] extern crate static_assertions; fn main() {}
123 /// assert_trait_sub_any!(PartialOrd: Eq, Clone);
124 /// ```
125 ///
126 /// [`assert_impl_any!`]: macro.assert_impl_any.html
127 ///
128 /// [`Copy`]:       https://doc.rust-lang.org/std/marker/trait.Copy.html
129 /// [`Clone`]:      https://doc.rust-lang.org/std/clone/trait.Clone.html
130 /// [`Ord`]:        https://doc.rust-lang.org/std/cmp/trait.Ord.html
131 /// [`PartialOrd`]: https://doc.rust-lang.org/std/cmp/trait.PartialOrd.html
132 /// [`Eq`]:         https://doc.rust-lang.org/std/cmp/trait.Eq.html
133 /// [`PartialEq`]:  https://doc.rust-lang.org/std/cmp/trait.PartialEq.html
134 #[macro_export(local_inner_macros)]
135 macro_rules! assert_trait_sub_any {
136     ($sub:path: $($super:path),+ $(,)?) => {
137         assert_impl!(for(T: $sub) T: $( ($super) )|+);
138     };
139 }
140