expand/
struct_string.rs

1// File: ./examples/expand/struct_string.rs
2// clear && cargo run --example expand --features ok -- struct_string
3// clear && cargo run --example expand --features err_04 -- struct_string
4// clear && cargo run --example expand --features err_05 -- struct_string
5
6//=======
7#![allow(unused_variables)]
8
9
10//=======
11#[cfg(feature = "ok")]
12pub fn adjoin() {
13    // ANCHOR: feature-ok
14    // File: ./examples/expand/struct_string.rs
15    // #[cfg(feature = "ok")]
16
17    #[derive(Clone)]
18    struct Struct(String);
19
20    let instance = Struct(String::from("Hello"));
21    let clone_instance = instance.clone();
22    let copy_instance = instance;
23
24    // can copy and clone, because derive *Clone*
25    // can not move, because without derive *Copy*,
26    // and instance live not, copy_instance live
27    let use_copy_instance = copy_instance;
28
29    // ANCHOR_END: feature-ok
30}
31
32
33//=======
34#[cfg(feature = "err_04")]
35pub fn adjoin() {
36    // ANCHOR: feature-error_01
37    // File: ./examples/expand/struct_string.rs
38    // ANCHOR = "struct_string-error_01"
39    // error[E0204]: the trait `Copy` may not be implemented for this type
40
41    #[derive(Clone, Copy)]
42    struct Struct(String);
43
44    let instance = Struct(String::from("Hello"));
45    let clone_instance = instance.clone();
46    let copy_instance = instance;
47
48    let use_instance = instance;
49
50    // ANCHOR_END: feature-error_01
51}
52
53
54//=======
55#[cfg(feature = "err_05")]
56pub fn adjoin() {
57    // ANCHOR: feature-error_02
58    // File: ./examples/expand/struct_string.rs
59    // ANCHOR = "struct_string-error_02"
60    // error[E0382]: use of moved value: `instance`
61
62    #[derive(Clone)]
63    struct Struct(String);
64
65    let instance = Struct(String::from("Hello"));
66    let clone_instance = instance.clone();
67    let copy_instance = instance;
68
69    // can copy and clone, because derive *Clone*
70    // but can NOT move, because without derive *Copy*,
71    // and instance live not
72    let use_instance = instance;
73
74    // ANCHOR_END: feature-error_02
75}
76
77
78//=======
79#[cfg(feature = "err_06")]
80pub fn adjoin() {
81    // ANCHOR: feature-error_03
82    // File: ./examples/expand/struct_string.rs
83    // ANCHOR = "struct_string-error_03"
84    // error[E0204]: the trait `Copy` may not be implemented for this type
85
86    #[derive(Copy)]
87    struct Struct(String);
88
89    let instance = Struct(String::from("Hello"));
90    let clone_instance = instance.clone();
91    let copy_instance = instance;
92
93    // copy exists, because derive *Clone*
94    // but can NOT move, because without derive *Copy*,
95    // and instance live not
96    let use_instance = instance;
97
98    // ANCHOR_END: feature-error_03
99}
100
101
102//=======
103#[cfg(all(
104    not(feature = "ok"),
105    not(feature = "err_04"),
106    not(feature = "err_05"),
107    not(feature = "err_06"),
108))]
109pub fn adjoin() {
110    use aide::*;
111    hello();
112}