Debian Codegraph @

debian/rust-vendor/defmt/tests/derive-bounds.rs

raw
1 #![allow(dead_code)]
2 extern crate defmt as defmt2;
3
4 fn main() {
5 let baz: Baz<Qux> = Default::default();
6 defmt::info!("{}", baz);
7 }
8
9 trait Foo {
10 type Bar;
11 }
12 #[derive(defmt::Format, Default)]
13 struct Baz<T: Foo> {
14 field: T::Bar,
15 field2: Quux<T>,
16 }
17 #[derive(defmt::Format, Default)]
18 struct Qux;
19 impl Foo for Qux {
20 type Bar = Qux;
21 }
22 #[allow(dead_code)]
23 #[derive(defmt::Format, Default)]
24 enum Quux<T: Foo> {
25 #[default]
26 None,
27 Variant1(T),
28 Variant2 {
29 f: T::Bar,
30 },
31 Variant3(T::Bar),
32 }
33
34 #[allow(dead_code)]
35 #[derive(defmt::Format)]
36 #[defmt(crate = defmt2)]
37 struct Quz;
38
39 #[derive(defmt::Format)]
40 #[defmt(transparent)]
41 #[allow(dead_code)]
42 enum TransparentEnum<T: Foo> {
43 Quz(Quz),
44 Quux(Quux<T>),
45 Baz(Baz<T>),
46 U16(u16),
47 }
48
49 #[derive(defmt::Format)]
50 #[defmt(transparent)]
51 #[allow(dead_code)]
52 struct Transparent<T: Foo>(Quux<T>);
53
54 #[derive(defmt::Format)]
55 #[defmt(transparent)]
56 #[defmt(transparent, crate = defmt4)]
57 #[defmt(crate = defmt3, crate = defmt2)]
58 #[allow(dead_code)]
59 struct Variations<T: Foo>(Quux<T>);
60
61 struct Flavor;
62
63 trait FlavorT {
64 type List<'a, T: 'a + ::defmt::Format>: ::defmt::Format;
65 }
66
67 impl FlavorT for Flavor {
68 type List<'a, T: 'a + ::defmt::Format> = &'a [T];
69 }
70
71 #[derive(defmt::Format)]
72 #[defmt(bound())] // fixes the compile error from `ui/derive_bound_overflow.rs`
73 enum Flavored<F: FlavorT + 'static> {
74 Str(F::List<'static, Self>),
75 }
76
77 const _: () = {
78 const fn implements_format<T: defmt::Format>() {}
79
80 implements_format::<Flavored<Flavor>>();
81 };