for_loop/
for_arr.rs

1// File: ./bin-hello/examples/for_loop/for_arr.rs
2// clear && cargo run --example for_loop --features ok -- for_arr | bat -l cmd
3// clear && cargo run --example for_loop --features err_01
4// clear && cargo run --example for_loop -- for_arr
5
6
7//=======
8
9
10//=======
11#[cfg(feature = "ok")]
12pub fn adjoin() {
13    // ANCHOR: feature-ok
14    // File: ./bin-hello/examples/for_loop/for_arr.rs
15    // #[cfg(feature = "ok")]
16
17    let instance = [1u8, 2, 3];
18    println!("{:>17} {} {:p}", "instance ref", "=", &instance);
19
20    print!("{:>17} {} ", "for ref", "=");
21    for item in &instance {
22        let ref_item: &u8 = item;
23        print!("{:p} ", ref_item);
24    }
25    println!("");
26
27    print!("{:>17} {} ", "for .iter()", "=");
28    for item in instance.iter() {
29        let ref_item: &u8 = item;
30        print!("{:p} ", ref_item);
31    }
32    println!("");
33
34    print!("{:>17} {} ", "for .into_iter()", "=");
35    for item in instance.into_iter() {
36        //let u8_item :u8 = item;  // ERROR: item IS &u8!!!
37        let ref_item: &u8 = item;
38        print!("{:p} ", ref_item);
39    }
40    println!("");
41
42    println!("{:>17} {} {:?}", "instance arr", "=", instance);
43
44    // ANCHOR_END: feature-ok
45}
46
47
48//=======
49#[cfg(feature = "err_01")]
50// error[E0277]
51pub fn adjoin() {
52    // ANCHOR: feature-err
53    // File: ./bin-hello/examples/for_loop/for_arr.rs
54    // #[cfg(feature = "err_01")]
55
56    let instance = [1u8, 2, 3];
57
58    for item in instance {
59        print!("{:p} ", item);
60    }
61
62    println!("instance array = {:?}", instance);
63
64    // ANCHOR_END: feature-err
65}
66
67
68//=======
69#[cfg(all(not(feature = "ok"), not(feature = "err_01")))]
70pub fn adjoin() {
71    use aide::hello;
72    hello();
73}