closure/kw_move.rs
1// File: ./bin-hello/examples/closure/kw_move/mod.rs
2// clear && cargo run --example closure --features ok -- kw_move | bat -l cmd
3// clear && cargo run --example closure --features err_02
4// clear && cargo run --example closure -- kw_move
5
6//=======
7
8
9//=======
10#[cfg(feature = "ok")]
11pub fn adjoin() {
12 // ANCHOR: feature-ok
13 // File: ./bin-hello/examples/closure/kw_move/mod.rs
14 // #[cfg(feature = "ok")]
15
16 let instance = vec![1, 2, 3];
17
18 // borrow this variable `instance`
19 (|| (instance.len()))();
20 //|| ( instance.len() );
21
22 println!("{:?}", instance); // ok; x was not moved
23
24 // ANCHOR_END: feature-ok
25}
26
27
28//=======
29#[cfg(feature = "cp")]
30pub fn adjoin() {
31 // ANCHOR: feature-cp
32 // File: ./bin-hello/examples/closure/kw_move/mod.rs
33 // #[cfg(feature = "cp")]
34
35 let instance = vec![1, 2, 3];
36
37 // borrow this variable `instance`
38 (|| {
39 (&instance);
40 })();
41 //|| { (&instance); };
42
43 // ok: x was not moved
44 println!("{:?}", instance);
45
46 // ANCHOR_END: feature-cp
47}
48
49
50//=======
51#[cfg(feature = "err_02")]
52pub fn adjoin() {
53 // ANCHOR: feature-err
54 // File: ./bin-hello/examples/closure/kw_move/mod.rs
55 // #[cfg(feature = "err_02")]
56
57 let instance = vec![1, 2, 3];
58
59 // move this variable `instance`
60 (move || {
61 (&instance);
62 })();
63 //( move || (instance.len()) )();
64 //move || { (&instance); };
65 //move || ( instance.len() );
66
67 // ERROR: x was moved
68 println!("{:?}", instance);
69
70 // ANCHOR_END: feature-err
71}
72
73
74//=======
75#[cfg(all(not(feature = "ok"), not(feature = "err_02"), not(feature = "cp")))]
76pub fn adjoin() {
77 use aide::hello;
78 hello();
79}