]>
git.proxmox.com Git - rustc.git/blob - src/doc/book/listings/ch04-understanding-ownership/listing-04-03/src/main.rs
2 let s
= String
::from("hello"); // s comes into scope
4 takes_ownership(s
); // s's value moves into the function...
5 // ... and so is no longer valid here
7 let x
= 5; // x comes into scope
9 makes_copy(x
); // x would move into the function,
10 // but i32 is Copy, so it's okay to still
13 } // Here, x goes out of scope, then s. But because s's value was moved, nothing
16 fn takes_ownership(some_string
: String
) { // some_string comes into scope
17 println
!("{}", some_string
);
18 } // Here, some_string goes out of scope and `drop` is called. The backing
21 fn makes_copy(some_integer
: i32) { // some_integer comes into scope
22 println
!("{}", some_integer
);
23 } // Here, some_integer goes out of scope. Nothing special happens.