closure/
move_vec.rs

1// File: ./bin-hello/examples/closure/move_vec/mod.rs
2// clear && cargo run --example closure --features ok -- move_vec | bat -l cmd
3// clear && cargo run --example closure --features err_03
4// clear && cargo run --example closure --features err_04
5// clear && cargo run --example closure -- move_vec
6
7//=======
8#![allow(unused_variables)]
9
10
11
12//=======
13#[cfg(feature = "ok")]
14pub fn adjoin() {
15    // ANCHOR: feature-ok
16    // File: ./bin-hello/examples/closure/move_vec/mod.rs
17    // #[cfg(feature = "ok")]
18
19    let instance = vec![1, 2, 3];
20
21    println!("The variable instance before borrowing: {:?}", instance);
22
23    let ref_instance = &instance;
24    let equal_to_val = move |input_var| input_var == ref_instance;
25
26    println!("The variable instance after borrowing: {:?}", instance);
27
28    // use this closure
29    let input_instance = vec![1, 2, 3];
30    assert!(equal_to_val(&input_instance));
31
32    // ANCHOR_END: feature-ok
33}
34
35//=======
36#[cfg(feature = "err_03")]
37pub fn adjoin() {
38    // ANCHOR: feature-err_03
39    // File: ./bin-hello/examples/closure/move_vec/mod.rs
40    // #[cfg(feature = "err_03")]
41
42    let instance = vec![1, 2, 3];
43    println!("The variable instance before borrowing: {:?}", instance);
44
45    // The variable instance begin to move here
46    let equal_to_val = move |input_var| input_var == &instance;
47    // The variable instance moved here
48
49    // The variable instance borrowed here after move
50    println!("The variable instance after borrowing: {:?}", instance);
51
52    // use this closure
53    let input_instance = vec![1, 2, 3];
54    assert!(equal_to_val(&input_instance));
55
56    // ANCHOR_END: feature-err_03
57}
58
59//=======
60#[cfg(feature = "err_04")]
61pub fn adjoin() {
62    // ANCHOR: feature-err_04
63    // File: ./bin-hello/examples/closure/move_vec/mod.rs
64    // #[cfg(feature = "err_04")]
65
66    let instance = vec![1, 2, 3];
67
68    println!("The variable instance before borrowing: {:?}", instance);
69    // The variable instance begin to move here
70    //let equal_to_val = move |input_var| {input_var == instance};
71    let equal_to_val = move |input_var| input_var == instance;
72    // The variable instance moved here
73
74    // The variable instance borrowed here after move
75    println!("The variable instance after borrowing: {:?}", instance);
76
77    // use this closure
78    let input_instance = vec![1, 2, 3];
79    assert!(equal_to_val(input_instance));
80
81    // ANCHOR_END: feature-err_04
82}
83
84//=======
85#[cfg(all(not(feature = "ok"), not(feature = "err_03"), not(feature = "err_04")))]
86pub fn adjoin() {
87    use aide::hello;
88    hello();
89}