for_loop/
for_into_iter.rs

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