for_loop/
for_iter_mut.rs

1// File: ./bin-hello/examples/for_loop/for_iter_mut.rs
2// clear && cargo run --example for_loop --features ok -- for_iter_mut | bat -l cmd
3// clear && cargo run --example for_loop --features err_04
4// clear && cargo run --example for_loop --features err_05
5// clear && cargo run --example for_loop -- for_iter_mut
6
7
8//=======
9
10
11//=======
12#[cfg(feature = "ok")]
13pub fn adjoin() {
14    // ANCHOR: feature-ok
15    // File: ./bin-hello/examples/for_loop/for_iter_mut.rs
16    // #[cfg(feature = "ok")]
17
18    let mut instance = vec![33u8, 42];
19    println!("1. instance = {:?}", instance);
20    println!("1. &instance = {:p}", &instance);
21
22    for item in instance.iter_mut() {
23        *item = 1;
24        println!("item = {:p}", item);
25    }
26
27    println!("2. instance = {:?}", instance);
28    println!("2. &instance = {:p}", &instance);
29
30    // ANCHOR_END: feature-ok
31}
32
33
34
35//=======
36#[cfg(feature = "cp")]
37pub fn adjoin() {
38    // ANCHOR: feature-cp
39    // File: ./bin-hello/examples/for_loop/for_iter_mut.rs
40    // #[cfg(feature = "cp")]
41
42    let mut instance = vec![33u8, 42];
43    println!("1. instance = {:?}", instance);
44    println!("1. &instance = {:p}", &instance);
45
46    let ref_instance = &mut instance;
47    println!("1. ref_instance = {:?}", ref_instance);
48    println!("1. ref_instance = {:p}", ref_instance);
49
50    for item in ref_instance.iter_mut() {
51        *item = 1;
52        println!("item = {:p}", item);
53    }
54
55    println!("2. ref_instance = {:?}", ref_instance);
56    println!("2. ref_instance = {:p}", ref_instance);
57    println!("2. instance = {:?}", instance);
58
59    // ANCHOR_END: feature-cp
60}
61
62
63
64
65//=======
66#[cfg(feature = "okey")]
67pub fn adjoin() {
68    // ANCHOR: feature-okey
69    // File: ./bin-hello/examples/for_loop/for_iter_mut.rs
70    // #[cfg(feature = "okey")]
71
72    let mut instance = vec![33u8, 42];
73    println!("1. instance = {:?}", instance);
74    println!("1. &instance = {:p}", &instance);
75
76    let ref_instance = &mut *instance;
77    println!("1. ref_instance = {:p}", ref_instance);
78    for item in ref_instance.iter_mut() {        
79        *item = 1;
80        println!("item = {:p}", item);
81    }
82
83    println!("2. ref_instance = {:p}", ref_instance);
84    println!("2. instance = {:?}", instance);
85
86    // ANCHOR_END: feature-okey
87}
88
89
90
91
92//=======
93#[cfg(feature = "okay")]
94pub fn adjoin() {
95    // ANCHOR: feature-okay
96    // File: ./bin-hello/examples/for_loop/for_iter_mut.rs
97    // #[cfg(feature = "okay")]
98
99    let mut instance = vec![33u8, 42];
100    println!("1. instance = {:?}", instance);
101    println!("1. &instance = {:p}", &instance);
102
103    let ref_instance = &mut instance;
104    println!("1. ref_instance = {:?}", ref_instance);
105    println!("1. ref_instance = {:p}", ref_instance);
106
107    for item in ref_instance.iter_mut() {
108        *item = 1;
109        println!("item = {:p}", item);
110    }
111    println!("2. ref_instance = {:?}", ref_instance);
112    println!("2. ref_instance = {:p}", ref_instance);
113
114    let ref_instance = &mut *instance;
115    println!("3. ref_instance = {:p}", ref_instance);
116    for item in ref_instance.iter_mut() {        
117        *item = 1;
118        println!("item = {:p}", item);
119    }
120
121    println!("3. ref_instance = {:?}", ref_instance);
122    println!("3. ref_instance = {:p}", ref_instance);
123    println!("2. instance = {:?}", instance);
124
125
126    // ANCHOR_END: feature-okay
127}
128
129
130
131//=======
132#[cfg(feature = "err_04")]
133pub fn adjoin() {
134    // ANCHOR: feature-error_01
135    // File: ./bin-hello/examples/for_loop/for_iter_mut.rs
136    // #[cfg(feature = "err_04")]
137
138    let mut instance = vec![33u8, 42];
139    let ref_instance = &mut instance;
140
141    for item in ref_instance {
142        *item = 1;
143    }
144
145    println!("{:?}", ref_instance); // ERROR
146    println!("{:?}", instance);
147
148    // ANCHOR_END: feature-error_01
149}
150
151
152
153//=======
154#[cfg(feature = "err_05")]
155pub fn adjoin() {
156    // ANCHOR: feature-error_02
157    // File: ./bin-hello/examples/for_loop/for_iter_mut.rs
158    // #[cfg(feature = "err_05")]
159
160    let mut instance = vec![33u8, 42];
161    let ref_instance = &mut *instance;
162
163    for item in ref_instance {
164        *item = 1;
165    }
166    
167    println!("{:?}", ref_instance); //ERROR
168    println!("{:?}", instance);
169
170    // ANCHOR_END: feature-error_02
171}
172
173
174
175//=======
176#[cfg(feature = "err_06")]
177pub fn adjoin() {
178    // ANCHOR: feature-error_03
179    // File: ./bin-hello/examples/for_loop/for_iter_mut.rs
180    // #[cfg(feature = "err_06")]
181
182    let mut instance = vec![33u8, 42];
183    println!("1. instance = {:?}", instance);
184
185    for item in instance.into_iter() {
186        item = 1;
187    }
188
189    println!("2. instance = {:?}", instance);
190
191    // ANCHOR_END: feature-err_06
192}
193
194
195
196//=======
197#[cfg(all(
198    not(feature = "ok"), 
199    not(feature = "okay"),
200    not(feature = "okey"),
201    not(feature = "cp"),
202    not(feature = "err_04"),
203    not(feature = "err_05"),
204    not(feature = "err_06"),
205))]
206pub fn adjoin() {
207    use aide::hello;
208    hello();
209}