-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a8eeff8
commit 9300823
Showing
5 changed files
with
50 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#[test] | ||
fn ex1_ww() { | ||
// a. copy | ||
let x = 5; | ||
let y = x; // !! copied, not moved | ||
println!("x: {}!", x); | ||
// Ok: Since because integers are simple values with a known, | ||
// fixed size, and these two 5 values are pushed onto the stack | ||
|
||
// b. move | ||
let s1 = String::from("hello"); | ||
let s2 = s1; // !! s1 moved to s2, s1 is invalid at this point | ||
// println!("s1: {}!", s1); | ||
// error[E0382]: borrow of moved value: `s1` | ||
// --> src/main.rs:15:25 | ||
// | | ||
// 12 | let s1 = String::from("hello"); | ||
// | -- move occurs because `s1` has type `String`, | ||
// which does not implement the `Copy` trait | ||
// 13 | let s2 = s1; | ||
// | -- value moved here | ||
// 14 | | ||
// 15 | println!("s1: {}!", s1); | ||
// | ^^ value borrowed here after move | ||
// | | ||
// help: consider cloning the value if the performance cost is acceptable | ||
// | | ||
// 13 | let s2 = s1.clone(); | ||
// | ++++++++ | ||
|
||
assert_eq!(32, 32); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
// Template - copy and change this: | ||
// | ||
// #[test] | ||
// #[test] | ||
// fn ex1_ww() { | ||
// assert_eq!(32,32); | ||
// assert_eq!(32, 32); | ||
// } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters