-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
ad25d35
commit 907315f
Showing
10 changed files
with
34 additions
and
34 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
listings/ch03-common-programming-concepts/no-listing-24-comments-end-of-line/src/main.rs
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,3 +1,3 @@ | ||
fn main() { | ||
let lucky_number = 7; // I’m feeling lucky today | ||
let lucky_number = 7; // I'm feeling lucky today | ||
} |
2 changes: 1 addition & 1 deletion
2
listings/ch03-common-programming-concepts/no-listing-25-comments-above-line/src/main.rs
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,4 +1,4 @@ | ||
fn main() { | ||
// I’m feeling lucky today | ||
// I'm feeling lucky today | ||
let lucky_number = 7; | ||
} |
31 changes: 16 additions & 15 deletions
31
listings/ch04-understanding-ownership/listing-04-04/src/main.rs
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,29 +1,30 @@ | ||
fn main() { | ||
let s1 = gives_ownership(); // gives_ownership moves its return | ||
// value into s1 | ||
let s1 = gives_ownership(); // gives_ownership moves its return | ||
// value into s1 | ||
|
||
let s2 = String::from("hello"); // s2 comes into scope | ||
let s2 = String::from("hello"); // s2 comes into scope | ||
|
||
let s3 = takes_and_gives_back(s2); // s2 is moved into | ||
// takes_and_gives_back, which also | ||
// moves its return value into s3 | ||
let s3 = takes_and_gives_back(s2); // s2 is moved into | ||
// takes_and_gives_back, which also | ||
// moves its return value into s3 | ||
} // Here, s3 goes out of scope and is dropped. s2 was moved, so nothing | ||
// happens. s1 goes out of scope and is dropped. | ||
|
||
fn gives_ownership() -> String { // gives_ownership will move its | ||
// return value into the function | ||
// that calls it | ||
fn gives_ownership() -> String { // gives_ownership will move its | ||
// return value into the function | ||
// that calls it | ||
|
||
let some_string = String::from("yours"); // some_string comes into scope | ||
|
||
some_string // some_string is returned and | ||
// moves out to the calling | ||
// function | ||
some_string // some_string is returned and | ||
// moves out to the calling | ||
// function | ||
} | ||
|
||
// This function takes a String and returns one | ||
fn takes_and_gives_back(a_string: String) -> String { // a_string comes into | ||
// scope | ||
// This function takes a String and returns a String. | ||
fn takes_and_gives_back(a_string: String) -> String { | ||
// a_string comes into | ||
// scope | ||
|
||
a_string // a_string is returned and moves out to the calling function | ||
} |
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
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
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
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