Debian Codegraph @

third_party/rust/derive_more/tests/generics.rs

raw
1 #![cfg_attr(not(feature = "std"), no_std)]
2 #![allow(dead_code, non_camel_case_types)]
3
4 use derive_more::{
5 Add, AddAssign, Constructor, Deref, DerefMut, Display, Error, From, FromStr, Index,
6 IndexMut, IntoIterator, Mul, MulAssign, Not, Sum,
7 };
8
9 #[derive(
10 From,
11 FromStr,
12 Display,
13 Index,
14 Not,
15 Add,
16 Mul,
17 Sum,
18 IndexMut,
19 AddAssign,
20 MulAssign,
21 Deref,
22 DerefMut,
23 IntoIterator,
24 Constructor
25 )]
26 #[deref(forward)]
27 #[deref_mut(forward)]
28 #[into_iterator(owned, ref, ref_mut)]
29 struct Wrapped<T: Clone>(T);
30
31 #[derive(Deref, DerefMut)]
32 struct Wrapped2<T: Clone>(T);
33
34 #[derive(From, Not, Add, Mul, AddAssign, MulAssign, Constructor, Sum)]
35 struct WrappedDouble<T: Clone, U: Clone>(T, U);
36
37 #[derive(From)]
38 #[from(forward)]
39 struct WrappedDouble2<T: Clone, U: Clone>(T, U);
40
41 #[cfg(nightly)]
42 #[derive(
43 From,
44 FromStr,
45 Display,
46 Index,
47 Not,
48 Add,
49 Mul,
50 Sum,
51 IndexMut,
52 AddAssign,
53 MulAssign,
54 Deref,
55 DerefMut,
56 IntoIterator,
57 Constructor
58 )]
59 struct WrappedWithConst<T, const C: u32>(T);
60
61 #[derive(
62 From,
63 FromStr,
64 Display,
65 Index,
66 Not,
67 Add,
68 Mul,
69 IndexMut,
70 AddAssign,
71 MulAssign,
72 Deref,
73 DerefMut,
74 IntoIterator,
75 Constructor,
76 Sum
77 )]
78 #[deref(forward)]
79 #[deref_mut(forward)]
80 #[into_iterator(owned, ref, ref_mut)]
81 struct Struct1<T: Clone> {
82 t: T,
83 }
84
85 #[derive(Deref, DerefMut)]
86 struct Struct2<T: Clone> {
87 t: T,
88 }
89
90 #[derive(From, Not, Add, Mul, AddAssign, MulAssign, Constructor, Sum)]
91 struct DoubleStruct<T: Clone, U: Clone> {
92 t: T,
93 u: U,
94 }
95
96 #[derive(From)]
97 #[from(forward)]
98 struct DoubleStruct2<T: Clone, U: Clone> {
99 t: T,
100 u: U,
101 }
102
103 #[derive(From, Not, Add)]
104 enum TupleEnum<T: Clone, U: Clone> {
105 Tuple(T),
106 DoubleTuple(T, U),
107 }
108
109 #[derive(From)]
110 #[from(forward)]
111 enum TupleEnum2<T: Clone, U: Clone, X: Clone> {
112 DoubleTuple(T, U),
113 TripleTuple(T, U, X),
114 }
115
116 #[derive(From, Not, Add)]
117 enum StructEnum<T: Clone, U: Clone> {
118 Struct { t: T },
119 DoubleStruct { t: T, u: U },
120 }
121
122 #[derive(From)]
123 #[from(forward)]
124 enum StructEnum2<T: Clone, U: Clone, X: Clone> {
125 DoubleStruct { t: T, u: U },
126 TripleStruct { t: T, u: U, x: X },
127 }
128
129 #[derive(Debug, Display, Error)]
130 enum Enum {}
131
132 #[derive(Debug, Display, Error)]
133 enum EnumGeneric<E> {
134 Inner(E),
135 }
136
137 #[derive(Debug, Display, Error)]
138 enum EnumConst<const X: usize> {}
139
140 #[derive(Debug, Display, Error)]
141 enum EnumConstDefault<const X: usize = 42> {}
142
143 #[derive(Debug, Display, Error)]
144 enum EnumLifetime<'lt: 'static> {
145 Inner(&'lt Enum),
146 }
147
148 #[derive(Debug, Display, Error)]
149 enum EnumConstGeneric<const X: usize, E> {
150 Inner(E),
151 }
152
153 #[derive(Debug, Display, Error)]
154 enum EnumGenericConst<E, const X: usize> {
155 Inner(E),
156 }
157
158 #[derive(Debug, Display, Error)]
159 enum EnumGenericConstDefault<E, const X: usize = 42> {
160 Inner(E),
161 }
162
163 #[derive(Debug, Display, Error)]
164 enum EnumLifetimeGeneric<'lt: 'static, E> {
165 Inner(&'lt E),
166 }
167
168 #[derive(Debug, Display, Error)]
169 enum EnumLifetimeConst<'lt: 'static, const X: usize> {
170 Inner(&'lt EnumConst<X>),
171 }
172
173 #[derive(Debug, Display, Error)]
174 enum EnumLifetimeConstDefault<'lt: 'static, const X: usize = 42> {
175 Inner(&'lt EnumConst<X>),
176 }
177
178 #[derive(Debug, Display, Error)]
179 enum EnumLifetimeConstGeneric<'lt: 'static, const X: usize, E> {
180 Inner(&'lt E),
181 }
182
183 #[derive(Debug, Display, Error)]
184 enum EnumLifetimeGenericConst<'lt: 'static, E, const X: usize> {
185 Inner(&'lt E),
186 }
187
188 #[derive(Debug, Display, Error)]
189 enum EnumLifetimeGenericConstDefault<'lt: 'static, E, const X: usize = 42> {
190 Inner(&'lt E),
191 }
192
193 #[derive(Debug, Display, Error)]
194 struct Struct;
195
196 #[derive(Debug, Display, Error)]
197 struct StructGeneric<E> {
198 inner: E,
199 }
200
201 #[derive(Debug, Display, Error)]
202 struct StructConst<const X: usize> {}
203
204 #[derive(Debug, Display, Error)]
205 struct StructConstDefault<const X: usize = 42> {}
206
207 #[derive(Debug, Display, Error)]
208 struct StructLifetime<'lt: 'static> {
209 inner: &'lt Enum,
210 }
211
212 #[derive(Debug, Display, Error)]
213 struct StructConstGeneric<const X: usize, E> {
214 inner: E,
215 }
216
217 #[derive(Debug, Display, Error)]
218 struct StructGenericConst<E, const X: usize> {
219 inner: E,
220 }
221
222 #[derive(Debug, Display, Error)]
223 struct StructGenericConstDefault<E, const X: usize = 42> {
224 inner: E,
225 }
226
227 #[derive(Debug, Display, Error)]
228 struct StructLifetimeGeneric<'lt: 'static, E> {
229 inner: &'lt E,
230 }
231
232 #[derive(Debug, Display, Error)]
233 struct StructLifetimeConst<'lt: 'static, const X: usize> {
234 inner: &'lt EnumConst<X>,
235 }
236
237 #[derive(Debug, Display, Error)]
238 struct StructLifetimeConstDefault<'lt: 'static, const X: usize = 42> {
239 inner: &'lt EnumConst<X>,
240 }
241
242 #[derive(Debug, Display, Error)]
243 struct StructLifetimeConstGeneric<'lt: 'static, const X: usize, E> {
244 inner: &'lt E,
245 }
246
247 #[derive(Debug, Display, Error)]
248 struct StructLifetimeGenericConst<'lt: 'static, E, const X: usize> {
249 inner: &'lt E,
250 }
251
252 #[derive(Debug, Display, Error)]
253 struct StructLifetimeGenericConstDefault<'lt: 'static, E, const X: usize = 42> {
254 inner: &'lt E,
255 }
256
257 #[derive(Debug, Display, Error)]
258 struct StructLifetimeGenericBoundsConstDefault<
259 'lt: 'static,
260 E: Clone,
261 const X: usize = 42,
262 > {
263 inner: &'lt E,
264 }