expand/
struct_str.rs

1// File: ./examples/expand/struct_str.rs
2// clear && cargo run --example expand --features ok -- struct_str
3// clear && cargo expand --example expand --features ok -- struct_str
4// clear && cargo run --example expand --features cp -- struct_str
5// clear && cargo expand --example expand --features cp -- struct_str
6// clear && cargo run --example expand --features err_06 -- struct_str
7// clear && cargo run --example expand --features err_07 -- struct_str
8// clear && cargo run --example expand --features err_08 -- struct_str
9// clear && cargo expand --example expand --features err_08 -- struct_str
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_str.rs
20    // #[cfg(feature = "ok")]
21
22    #[derive(Clone, Copy)]
23    struct Struct<'cn>(&'cn str);
24
25    let instance: Struct = Struct("Hello");
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_str.rs
43    // #[cfg(feature = "cp")]
44
45    #[derive(Clone)]
46    struct Struct<'cn>(&'cn str);
47
48    let instance: Struct = Struct("Hello");
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_07")]
63pub fn adjoin() {
64    // ANCHOR: feature-error_01
65    // File: ./examples/expand/struct_str.rs
66    // ANCHOR = "struct_str-error_01"
67    // error[E0382]: use of moved value: `instance`
68
69    #[derive(Clone)]
70    struct Struct<'cn>(&'cn str);
71
72    let instance: Struct = Struct("Hello");
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    //dbg!(instance.0, clone_instance.0, copy_instance.0);
81
82    // ANCHOR_END: feature-error_01
83}
84
85
86//=======
87#[cfg(feature = "err_08")]
88pub fn adjoin() {
89    // ANCHOR: feature-error_02
90    // File: ./examples/expand/struct_str.rs
91    // ANCHOR = "struct_str-error_02"
92    // error[E0382]: use of moved value: `instance`
93
94    #[derive(Clone)]
95    struct Struct<'cn>(&'cn str);
96
97    let instance: Struct = Struct("Hello");
98    let clone_instance = instance.clone();
99    let copy_instance = instance;
100
101    // can copy and clone, because derive *Clone*
102    // but can NOT move, because without derive *Copy*,
103    // and instance live not, but copy_instance live
104    let use_copy_instance = copy_instance;
105    let use_instance = instance;
106
107    // ANCHOR_END: feature-error_02
108}
109
110
111//=======
112#[cfg(feature = "err_09")]
113pub fn adjoin() {
114    // ANCHOR: feature-error_03
115    // File: ./examples/expand/struct_str.rs
116    // ANCHOR = "struct_str-error_03"
117    // error[E0277]: the trait bound `struct_str::adjoin::Struct<'cn>: std::clone::Clone` is not satisfied
118
119    #[derive(Copy)]
120    struct Struct<'cn>(&'cn str);
121
122    let instance: Struct = Struct("Hello");
123    let clone_instance = instance.clone();
124    let copy_instance = instance;
125
126    // derive *Copy* error, because without derive *Clone*
127    let use_instance = instance;
128    //dbg!(instance.0, clone_instance.0, copy_instance.0);
129
130    // ANCHOR_END: feature-error_03
131}
132
133
134//=======
135#[cfg(all(
136    not(feature = "ok"),
137    not(feature = "cp"),
138    not(feature = "err_06"),
139    not(feature = "err_07"),
140    not(feature = "err_08"),
141))]
142pub fn adjoin() {
143    use aide::*;
144    hello();
145}