stack_head/
stack_head.rs

1#![allow(unused)]
2
3#[cfg(feature = "ok")]
4fn main() {
5    let i = 42;
6    let copy_i = i;
7    println!("{}", i);
8    println!("{}", copy_i);
9
10    let v = vec![1, 2, 3, 4];
11    let moved_v = v.clone();
12    println!("{:?}", v);
13    println!("{:?}", moved_v);
14
15    #[derive(Debug, Clone)]
16    struct Pair(u8);
17    let pair = Pair(1);
18    println!("original: {:?}", pair);
19    let moved_pair = pair.clone();
20    println!("copy: {:?}", moved_pair);
21    println!("original: {:?}", pair);
22}
23
24// error[E0382]
25#[cfg(feature = "err")]
26fn main() {
27    // allocated on the stack,
28    // the actual value is copied, instead of transferring ownership.
29    let i = 42;
30    let copy_i = i;
31    println!("{}", i);
32    println!("{}", copy_i);
33
34    // allocated on the heap,
35    // the ownership is transferred
36    let v = vec![1, 2, 3, 4];
37    let moved_v = v; // value moved here
38    println!("{:?}", v); // value borrowed here after move
39    println!("{:?}", moved_v);
40
41    #[derive(Debug, Clone)]
42    struct Pair(u8);
43    let pair = Pair(1);
44    println!("original: {:?}", pair);
45    let moved_pair = pair;
46    println!("copy: {:?}", moved_pair);
47    println!("original: {:?}", pair);
48}
49
50#[cfg(all(not(feature = "ok"), not(feature = "err")))]
51fn main() {
52    use aide::*;
53    hello();
54}