expand/struct_u8.rs
1// File: ./examples/expand/struct_u8.rs
2// clear && cargo run --example expand --features ok -- struct_u8
3// clear && cargo expand --example expand --features ok -- struct_u8
4// clear && cargo run --example expand --features cp -- struct_u8
5// clear && cargo expand --example expand --features cp -- struct_u8
6// clear && cargo run --example expand --features err_01 -- struct_u8
7// clear && cargo run --example expand --features err_02 -- struct_u8
8// clear && cargo run --example expand --features err_03 -- struct_u8
9// clear && cargo expand --example expand --features err_03 -- struct_u8
10
11//=======
12#![allow(unused_variables)]
13
14
15//=======
16#[cfg(feature = "ok")]
17pub fn adjoin() {
18 // ANCHOR: feature-ok
19 // File: ./examples/expand/struct_u8.rs
20 // #[cfg(feature = "ok")]
21
22 #[derive(Clone, Copy)]
23 struct Struct(u8);
24
25 let instance: Struct = Struct(42u8);
26 let clone_instance = instance.clone();
27 let copy_instance = instance;
28
29 // can copy and clone, because derive *Clone*
30 // can move, because derive *Copy*,
31 // and instance and copy_instance live
32 let use_instance = instance;
33
34 // ANCHOR_END: feature-ok
35}
36
37
38//=======
39#[cfg(feature = "cp")]
40pub fn adjoin() {
41 // ANCHOR: feature-cp
42 // File: ./examples/expand/struct_u8.rs
43 // #[cfg(feature = "cp")]
44
45 #[derive(Clone)]
46 struct Struct(u8);
47
48 let instance = Struct(42u8);
49 let clone_instance = instance.clone();
50 let copy_instance = instance;
51
52 // can copy and clone, because derive *Clone*
53 // but can NOT move, because without derive *Copy*,
54 // and instance live not, but copy_instance live
55 let use_copy_instance = copy_instance;
56
57 // ANCHOR_END: feature-cp
58}
59
60
61//=======
62#[cfg(feature = "err_01")]
63pub fn adjoin() {
64 // ANCHOR: feature-error_01
65 // File: ./examples/expand/struct_u8.rs
66 // ANCHOR = "struct_u8_error_01"
67 // error[E0382]: use of moved value: `instance`
68
69 #[derive(Clone)]
70 struct Struct(u8);
71
72 let instance = Struct(42u8);
73 let clone_instance = instance.clone();
74 let copy_instance = instance;
75
76 // can copy and clone, because derive *Clone*
77 // but can NOT move, because without derive *Copy*,
78 // and instance live not
79 let use_instance = instance;
80
81 // ANCHOR_END: feature-error_01
82}
83
84
85//=======
86#[cfg(feature = "err_02")]
87pub fn adjoin() {
88 // ANCHOR: feature-error_02
89 // File: ./examples/expand/struct_u8.rs
90 // ANCHOR = "struct_u8_error_02"
91 // error[E0382]: use of moved value: `instance`
92
93 #[derive(Clone)]
94 struct Struct(u8);
95
96 let instance = Struct(42u8);
97 let clone_instance = instance.clone();
98 let copy_instance = instance;
99
100 // can copy and clone, because derive *Clone*
101 // but can NOT move, because without derive *Copy*,
102 // and instance live not, but copy_instance live
103 let use_copy_instance = copy_instance;
104 let use_instance = instance;
105
106 // ANCHOR_END: feature-error_02
107}
108
109
110//=======
111#[cfg(feature = "err_03")]
112pub fn adjoin() {
113 // ANCHOR: feature-error_03
114 // File: ./examples/expand/struct_u8.rs
115 // ANCHOR = "struct_u8_error_03"
116 // error[E0277]: the trait bound `struct_u8::adjoin::Struct: std::clone::Clone` is not satisfied
117
118 #[derive(Copy)]
119 struct Struct(u8);
120
121 let instance = Struct(42u8);
122 let clone_instance = instance.clone();
123 let copy_instance = instance;
124
125 // derive *Copy* error, because without derive *Clone*
126 let use_instance = instance;
127
128 // ANCHOR_END: feature-error_03
129}
130
131
132//=======
133#[cfg(feature = "err_10")]
134pub fn adjoin() {
135 // ANCHOR: feature-error_04
136 // File: ./examples/expand/struct_u8.rs
137 // ANCHOR = "struct_u8_error_04"
138 // error[E0382]: use of moved value: `instance`
139
140 struct Struct(u8);
141
142 let instance = Struct(42u8);
143 let copy_instance = instance;
144
145 let use_instance = instance;
146
147 // ANCHOR_END: feature-error_04
148}
149
150
151//=======
152#[cfg(all(
153 not(feature = "ok"),
154 not(feature = "cp"),
155 not(feature = "err_01"),
156 not(feature = "err_02"),
157 not(feature = "err_03"),
158 not(feature = "err_10"),
159))]
160pub fn adjoin() {
161 use aide::*;
162 hello();
163}