diff --git a/listings/ch03-common-programming-concepts/listing-03-01/Cargo.toml b/listings/ch03-common-programming-concepts/listing-03-01/Cargo.toml index 291680c..10f4053 100644 --- a/listings/ch03-common-programming-concepts/listing-03-01/Cargo.toml +++ b/listings/ch03-common-programming-concepts/listing-03-01/Cargo.toml @@ -1,7 +1,6 @@ [package] name = "functions" version = "0.1.0" -authors = ["Your Name "] edition = "2018" [dependencies] diff --git a/listings/ch03-common-programming-concepts/listing-03-02/Cargo.toml b/listings/ch03-common-programming-concepts/listing-03-02/Cargo.toml index 8ddf691..71c3f86 100644 --- a/listings/ch03-common-programming-concepts/listing-03-02/Cargo.toml +++ b/listings/ch03-common-programming-concepts/listing-03-02/Cargo.toml @@ -1,7 +1,6 @@ [package] name = "branches" version = "0.1.0" -authors = ["Your Name "] edition = "2018" [dependencies] diff --git a/listings/ch03-common-programming-concepts/listing-03-03/Cargo.toml b/listings/ch03-common-programming-concepts/listing-03-03/Cargo.toml index b5ed848..9a198d7 100644 --- a/listings/ch03-common-programming-concepts/listing-03-03/Cargo.toml +++ b/listings/ch03-common-programming-concepts/listing-03-03/Cargo.toml @@ -1,7 +1,6 @@ [package] name = "loops" version = "0.1.0" -authors = ["Your Name "] edition = "2018" [dependencies] diff --git a/listings/ch03-common-programming-concepts/listing-03-04/Cargo.toml b/listings/ch03-common-programming-concepts/listing-03-04/Cargo.toml index b5ed848..9a198d7 100644 --- a/listings/ch03-common-programming-concepts/listing-03-04/Cargo.toml +++ b/listings/ch03-common-programming-concepts/listing-03-04/Cargo.toml @@ -1,7 +1,6 @@ [package] name = "loops" version = "0.1.0" -authors = ["Your Name "] edition = "2018" [dependencies] diff --git a/listings/ch03-common-programming-concepts/listing-03-05/Cargo.toml b/listings/ch03-common-programming-concepts/listing-03-05/Cargo.toml index b5ed848..9a198d7 100644 --- a/listings/ch03-common-programming-concepts/listing-03-05/Cargo.toml +++ b/listings/ch03-common-programming-concepts/listing-03-05/Cargo.toml @@ -1,7 +1,6 @@ [package] name = "loops" version = "0.1.0" -authors = ["Your Name "] edition = "2018" [dependencies] diff --git a/listings/ch03-common-programming-concepts/listing-03-05/src/main.rs b/listings/ch03-common-programming-concepts/listing-03-05/src/main.rs index 6e3cca6..5eaa7a0 100644 --- a/listings/ch03-common-programming-concepts/listing-03-05/src/main.rs +++ b/listings/ch03-common-programming-concepts/listing-03-05/src/main.rs @@ -1,7 +1,7 @@ fn main() { let a = [10, 20, 30, 40, 50]; - for element in a.iter() { + for element in a { println!("the value is: {}", element); } } diff --git a/listings/ch03-common-programming-concepts/no-listing-01-variables-are-immutable/Cargo.toml b/listings/ch03-common-programming-concepts/no-listing-01-variables-are-immutable/Cargo.toml index 7915d39..91a7dd9 100644 --- a/listings/ch03-common-programming-concepts/no-listing-01-variables-are-immutable/Cargo.toml +++ b/listings/ch03-common-programming-concepts/no-listing-01-variables-are-immutable/Cargo.toml @@ -1,7 +1,6 @@ [package] name = "variables" version = "0.1.0" -authors = ["Your Name "] edition = "2018" [dependencies] diff --git a/listings/ch03-common-programming-concepts/no-listing-01-variables-are-immutable/output.txt b/listings/ch03-common-programming-concepts/no-listing-01-variables-are-immutable/output.txt index 7c2ec5b..2b7e562 100644 --- a/listings/ch03-common-programming-concepts/no-listing-01-variables-are-immutable/output.txt +++ b/listings/ch03-common-programming-concepts/no-listing-01-variables-are-immutable/output.txt @@ -7,14 +7,10 @@ error[E0384]: cannot assign twice to immutable variable `x` | - | | | first assignment to `x` - | help: make this binding mutable: `mut x` + | help: consider making this binding mutable: `mut x` 3 | println!("The value of x is: {}", x); 4 | x = 6; | ^^^^^ cannot assign twice to immutable variable -error: aborting due to previous error - For more information about this error, try `rustc --explain E0384`. -error: could not compile `variables` - -To learn more, run the command again with --verbose. +error: could not compile `variables` due to previous error diff --git a/listings/ch03-common-programming-concepts/no-listing-02-adding-mut/Cargo.toml b/listings/ch03-common-programming-concepts/no-listing-02-adding-mut/Cargo.toml index 7915d39..91a7dd9 100644 --- a/listings/ch03-common-programming-concepts/no-listing-02-adding-mut/Cargo.toml +++ b/listings/ch03-common-programming-concepts/no-listing-02-adding-mut/Cargo.toml @@ -1,7 +1,6 @@ [package] name = "variables" version = "0.1.0" -authors = ["Your Name "] edition = "2018" [dependencies] diff --git a/listings/ch03-common-programming-concepts/no-listing-03-shadowing/Cargo.toml b/listings/ch03-common-programming-concepts/no-listing-03-shadowing/Cargo.toml index 7915d39..91a7dd9 100644 --- a/listings/ch03-common-programming-concepts/no-listing-03-shadowing/Cargo.toml +++ b/listings/ch03-common-programming-concepts/no-listing-03-shadowing/Cargo.toml @@ -1,7 +1,6 @@ [package] name = "variables" version = "0.1.0" -authors = ["Your Name "] edition = "2018" [dependencies] diff --git a/listings/ch03-common-programming-concepts/no-listing-03-shadowing/output.txt b/listings/ch03-common-programming-concepts/no-listing-03-shadowing/output.txt index 64ac2bf..f310e9f 100644 --- a/listings/ch03-common-programming-concepts/no-listing-03-shadowing/output.txt +++ b/listings/ch03-common-programming-concepts/no-listing-03-shadowing/output.txt @@ -2,4 +2,5 @@ $ cargo run Compiling variables v0.1.0 (file:///projects/variables) Finished dev [unoptimized + debuginfo] target(s) in 0.31s Running `target/debug/variables` -The value of x is: 12 +The value of x in the inner scope is: 12 +The value of x is: 6 diff --git a/listings/ch03-common-programming-concepts/no-listing-03-shadowing/src/main.rs b/listings/ch03-common-programming-concepts/no-listing-03-shadowing/src/main.rs index d325180..606ee68 100644 --- a/listings/ch03-common-programming-concepts/no-listing-03-shadowing/src/main.rs +++ b/listings/ch03-common-programming-concepts/no-listing-03-shadowing/src/main.rs @@ -3,7 +3,10 @@ fn main() { let x = x + 1; - let x = x * 2; + { + let x = x * 2; + println!("The value of x in the inner scope is: {}", x); + } println!("The value of x is: {}", x); } diff --git a/listings/ch03-common-programming-concepts/no-listing-04-shadowing-can-change-types/Cargo.toml b/listings/ch03-common-programming-concepts/no-listing-04-shadowing-can-change-types/Cargo.toml index 7915d39..91a7dd9 100644 --- a/listings/ch03-common-programming-concepts/no-listing-04-shadowing-can-change-types/Cargo.toml +++ b/listings/ch03-common-programming-concepts/no-listing-04-shadowing-can-change-types/Cargo.toml @@ -1,7 +1,6 @@ [package] name = "variables" version = "0.1.0" -authors = ["Your Name "] edition = "2018" [dependencies] diff --git a/listings/ch03-common-programming-concepts/no-listing-05-mut-cant-change-types/Cargo.toml b/listings/ch03-common-programming-concepts/no-listing-05-mut-cant-change-types/Cargo.toml index 7915d39..91a7dd9 100644 --- a/listings/ch03-common-programming-concepts/no-listing-05-mut-cant-change-types/Cargo.toml +++ b/listings/ch03-common-programming-concepts/no-listing-05-mut-cant-change-types/Cargo.toml @@ -1,7 +1,6 @@ [package] name = "variables" version = "0.1.0" -authors = ["Your Name "] edition = "2018" [dependencies] diff --git a/listings/ch03-common-programming-concepts/no-listing-05-mut-cant-change-types/output.txt b/listings/ch03-common-programming-concepts/no-listing-05-mut-cant-change-types/output.txt index 166b079..8701a07 100644 --- a/listings/ch03-common-programming-concepts/no-listing-05-mut-cant-change-types/output.txt +++ b/listings/ch03-common-programming-concepts/no-listing-05-mut-cant-change-types/output.txt @@ -6,9 +6,5 @@ error[E0308]: mismatched types 3 | spaces = spaces.len(); | ^^^^^^^^^^^^ expected `&str`, found `usize` -error: aborting due to previous error - For more information about this error, try `rustc --explain E0308`. -error: could not compile `variables` - -To learn more, run the command again with --verbose. +error: could not compile `variables` due to previous error diff --git a/listings/ch03-common-programming-concepts/no-listing-06-floating-point/Cargo.toml b/listings/ch03-common-programming-concepts/no-listing-06-floating-point/Cargo.toml index 81e80c2..3f4af9c 100644 --- a/listings/ch03-common-programming-concepts/no-listing-06-floating-point/Cargo.toml +++ b/listings/ch03-common-programming-concepts/no-listing-06-floating-point/Cargo.toml @@ -1,7 +1,6 @@ [package] name = "floating-point" version = "0.1.0" -authors = ["Your Name "] edition = "2018" [dependencies] diff --git a/listings/ch03-common-programming-concepts/no-listing-07-numeric-operations/Cargo.toml b/listings/ch03-common-programming-concepts/no-listing-07-numeric-operations/Cargo.toml index 00601dd..b1d25f2 100644 --- a/listings/ch03-common-programming-concepts/no-listing-07-numeric-operations/Cargo.toml +++ b/listings/ch03-common-programming-concepts/no-listing-07-numeric-operations/Cargo.toml @@ -1,7 +1,6 @@ [package] name = "numeric-operations" version = "0.1.0" -authors = ["Your Name "] edition = "2018" [dependencies] diff --git a/listings/ch03-common-programming-concepts/no-listing-07-numeric-operations/src/main.rs b/listings/ch03-common-programming-concepts/no-listing-07-numeric-operations/src/main.rs index 0a784bb..9d3b481 100644 --- a/listings/ch03-common-programming-concepts/no-listing-07-numeric-operations/src/main.rs +++ b/listings/ch03-common-programming-concepts/no-listing-07-numeric-operations/src/main.rs @@ -10,6 +10,7 @@ fn main() { // division let quotient = 56.7 / 32.2; + let floored = 2 / 3; // Results in 0 // remainder let remainder = 43 % 5; diff --git a/listings/ch03-common-programming-concepts/no-listing-08-boolean/Cargo.toml b/listings/ch03-common-programming-concepts/no-listing-08-boolean/Cargo.toml index 783df3d..c0d2257 100644 --- a/listings/ch03-common-programming-concepts/no-listing-08-boolean/Cargo.toml +++ b/listings/ch03-common-programming-concepts/no-listing-08-boolean/Cargo.toml @@ -1,7 +1,6 @@ [package] name = "boolean" version = "0.1.0" -authors = ["Your Name "] edition = "2018" [dependencies] diff --git a/listings/ch03-common-programming-concepts/no-listing-08-boolean/src/main.rs b/listings/ch03-common-programming-concepts/no-listing-08-boolean/src/main.rs index 4791d4e..2c56e62 100644 --- a/listings/ch03-common-programming-concepts/no-listing-08-boolean/src/main.rs +++ b/listings/ch03-common-programming-concepts/no-listing-08-boolean/src/main.rs @@ -1,5 +1,5 @@ fn main() { let t = true; - let f: bool = false; // 使用显式类型标注 + let f: bool = false; // with explicit type annotation } diff --git a/listings/ch03-common-programming-concepts/no-listing-09-char/Cargo.toml b/listings/ch03-common-programming-concepts/no-listing-09-char/Cargo.toml index cfde83b..37fdd73 100644 --- a/listings/ch03-common-programming-concepts/no-listing-09-char/Cargo.toml +++ b/listings/ch03-common-programming-concepts/no-listing-09-char/Cargo.toml @@ -1,7 +1,6 @@ [package] name = "char" version = "0.1.0" -authors = ["Your Name "] edition = "2018" [dependencies] diff --git a/listings/ch03-common-programming-concepts/no-listing-10-tuples/Cargo.toml b/listings/ch03-common-programming-concepts/no-listing-10-tuples/Cargo.toml index 8d6c2d5..01138c6 100644 --- a/listings/ch03-common-programming-concepts/no-listing-10-tuples/Cargo.toml +++ b/listings/ch03-common-programming-concepts/no-listing-10-tuples/Cargo.toml @@ -1,7 +1,6 @@ [package] name = "tuples" version = "0.1.0" -authors = ["Your Name "] edition = "2018" [dependencies] diff --git a/listings/ch03-common-programming-concepts/no-listing-11-destructuring-tuples/Cargo.toml b/listings/ch03-common-programming-concepts/no-listing-11-destructuring-tuples/Cargo.toml index 8d6c2d5..01138c6 100644 --- a/listings/ch03-common-programming-concepts/no-listing-11-destructuring-tuples/Cargo.toml +++ b/listings/ch03-common-programming-concepts/no-listing-11-destructuring-tuples/Cargo.toml @@ -1,7 +1,6 @@ [package] name = "tuples" version = "0.1.0" -authors = ["Your Name "] edition = "2018" [dependencies] diff --git a/listings/ch03-common-programming-concepts/no-listing-12-tuple-indexing/Cargo.toml b/listings/ch03-common-programming-concepts/no-listing-12-tuple-indexing/Cargo.toml index 8d6c2d5..01138c6 100644 --- a/listings/ch03-common-programming-concepts/no-listing-12-tuple-indexing/Cargo.toml +++ b/listings/ch03-common-programming-concepts/no-listing-12-tuple-indexing/Cargo.toml @@ -1,7 +1,6 @@ [package] name = "tuples" version = "0.1.0" -authors = ["Your Name "] edition = "2018" [dependencies] diff --git a/listings/ch03-common-programming-concepts/no-listing-13-arrays/Cargo.toml b/listings/ch03-common-programming-concepts/no-listing-13-arrays/Cargo.toml index ec97b7d..61bd758 100644 --- a/listings/ch03-common-programming-concepts/no-listing-13-arrays/Cargo.toml +++ b/listings/ch03-common-programming-concepts/no-listing-13-arrays/Cargo.toml @@ -1,7 +1,6 @@ [package] name = "arrays" version = "0.1.0" -authors = ["Your Name "] edition = "2018" [dependencies] diff --git a/listings/ch03-common-programming-concepts/no-listing-14-array-indexing/Cargo.toml b/listings/ch03-common-programming-concepts/no-listing-14-array-indexing/Cargo.toml index ec97b7d..61bd758 100644 --- a/listings/ch03-common-programming-concepts/no-listing-14-array-indexing/Cargo.toml +++ b/listings/ch03-common-programming-concepts/no-listing-14-array-indexing/Cargo.toml @@ -1,7 +1,6 @@ [package] name = "arrays" version = "0.1.0" -authors = ["Your Name "] edition = "2018" [dependencies] diff --git a/listings/ch03-common-programming-concepts/no-listing-15-invalid-array-access/Cargo.toml b/listings/ch03-common-programming-concepts/no-listing-15-invalid-array-access/Cargo.toml index ec97b7d..61bd758 100644 --- a/listings/ch03-common-programming-concepts/no-listing-15-invalid-array-access/Cargo.toml +++ b/listings/ch03-common-programming-concepts/no-listing-15-invalid-array-access/Cargo.toml @@ -1,7 +1,6 @@ [package] name = "arrays" version = "0.1.0" -authors = ["Your Name "] edition = "2018" [dependencies] diff --git a/listings/ch03-common-programming-concepts/no-listing-16-functions/Cargo.toml b/listings/ch03-common-programming-concepts/no-listing-16-functions/Cargo.toml index 291680c..10f4053 100644 --- a/listings/ch03-common-programming-concepts/no-listing-16-functions/Cargo.toml +++ b/listings/ch03-common-programming-concepts/no-listing-16-functions/Cargo.toml @@ -1,7 +1,6 @@ [package] name = "functions" version = "0.1.0" -authors = ["Your Name "] edition = "2018" [dependencies] diff --git a/listings/ch03-common-programming-concepts/no-listing-17-functions-with-parameters/Cargo.toml b/listings/ch03-common-programming-concepts/no-listing-17-functions-with-parameters/Cargo.toml index 291680c..10f4053 100644 --- a/listings/ch03-common-programming-concepts/no-listing-17-functions-with-parameters/Cargo.toml +++ b/listings/ch03-common-programming-concepts/no-listing-17-functions-with-parameters/Cargo.toml @@ -1,7 +1,6 @@ [package] name = "functions" version = "0.1.0" -authors = ["Your Name "] edition = "2018" [dependencies] diff --git a/listings/ch03-common-programming-concepts/no-listing-18-functions-with-multiple-parameters/Cargo.toml b/listings/ch03-common-programming-concepts/no-listing-18-functions-with-multiple-parameters/Cargo.toml index 291680c..10f4053 100644 --- a/listings/ch03-common-programming-concepts/no-listing-18-functions-with-multiple-parameters/Cargo.toml +++ b/listings/ch03-common-programming-concepts/no-listing-18-functions-with-multiple-parameters/Cargo.toml @@ -1,7 +1,6 @@ [package] name = "functions" version = "0.1.0" -authors = ["Your Name "] edition = "2018" [dependencies] diff --git a/listings/ch03-common-programming-concepts/no-listing-18-functions-with-multiple-parameters/output.txt b/listings/ch03-common-programming-concepts/no-listing-18-functions-with-multiple-parameters/output.txt index d651191..6210234 100644 --- a/listings/ch03-common-programming-concepts/no-listing-18-functions-with-multiple-parameters/output.txt +++ b/listings/ch03-common-programming-concepts/no-listing-18-functions-with-multiple-parameters/output.txt @@ -2,5 +2,4 @@ $ cargo run Compiling functions v0.1.0 (file:///projects/functions) Finished dev [unoptimized + debuginfo] target(s) in 0.31s Running `target/debug/functions` -The value of x is: 5 -The value of y is: 6 +The measurement is: 5h diff --git a/listings/ch03-common-programming-concepts/no-listing-18-functions-with-multiple-parameters/src/main.rs b/listings/ch03-common-programming-concepts/no-listing-18-functions-with-multiple-parameters/src/main.rs index fe476db..543c2ea 100644 --- a/listings/ch03-common-programming-concepts/no-listing-18-functions-with-multiple-parameters/src/main.rs +++ b/listings/ch03-common-programming-concepts/no-listing-18-functions-with-multiple-parameters/src/main.rs @@ -1,8 +1,7 @@ fn main() { - another_function(5, 6); + print_labeled_measurement(5, 'h'); } -fn another_function(x: i32, y: i32) { - println!("The value of x is: {}", x); - println!("The value of y is: {}", y); +fn print_labeled_measurement(value: i32, unit_label: char) { + println!("The measurement is: {}{}", value, unit_label); } diff --git a/listings/ch03-common-programming-concepts/no-listing-19-statements-vs-expressions/Cargo.toml b/listings/ch03-common-programming-concepts/no-listing-19-statements-vs-expressions/Cargo.toml index 291680c..10f4053 100644 --- a/listings/ch03-common-programming-concepts/no-listing-19-statements-vs-expressions/Cargo.toml +++ b/listings/ch03-common-programming-concepts/no-listing-19-statements-vs-expressions/Cargo.toml @@ -1,7 +1,6 @@ [package] name = "functions" version = "0.1.0" -authors = ["Your Name "] edition = "2018" [dependencies] diff --git a/listings/ch03-common-programming-concepts/no-listing-19-statements-vs-expressions/output.txt b/listings/ch03-common-programming-concepts/no-listing-19-statements-vs-expressions/output.txt index 7409e85..a3a52db 100644 --- a/listings/ch03-common-programming-concepts/no-listing-19-statements-vs-expressions/output.txt +++ b/listings/ch03-common-programming-concepts/no-listing-19-statements-vs-expressions/output.txt @@ -25,9 +25,6 @@ warning: unnecessary parentheses around assigned value | = note: `#[warn(unused_parens)]` on by default -error: aborting due to 2 previous errors; 1 warning emitted - For more information about this error, try `rustc --explain E0658`. -error: could not compile `functions` - -To learn more, run the command again with --verbose. +warning: `functions` (bin "functions") generated 1 warning +error: could not compile `functions` due to 2 previous errors; 1 warning emitted diff --git a/listings/ch03-common-programming-concepts/no-listing-20-blocks-are-expressions/Cargo.toml b/listings/ch03-common-programming-concepts/no-listing-20-blocks-are-expressions/Cargo.toml index 291680c..10f4053 100644 --- a/listings/ch03-common-programming-concepts/no-listing-20-blocks-are-expressions/Cargo.toml +++ b/listings/ch03-common-programming-concepts/no-listing-20-blocks-are-expressions/Cargo.toml @@ -1,7 +1,6 @@ [package] name = "functions" version = "0.1.0" -authors = ["Your Name "] edition = "2018" [dependencies] diff --git a/listings/ch03-common-programming-concepts/no-listing-20-blocks-are-expressions/src/main.rs b/listings/ch03-common-programming-concepts/no-listing-20-blocks-are-expressions/src/main.rs index baa853e..0be7fcb 100644 --- a/listings/ch03-common-programming-concepts/no-listing-20-blocks-are-expressions/src/main.rs +++ b/listings/ch03-common-programming-concepts/no-listing-20-blocks-are-expressions/src/main.rs @@ -1,6 +1,4 @@ fn main() { - let x = 5; - let y = { let x = 3; x + 1 diff --git a/listings/ch03-common-programming-concepts/no-listing-21-function-return-values/Cargo.toml b/listings/ch03-common-programming-concepts/no-listing-21-function-return-values/Cargo.toml index 291680c..10f4053 100644 --- a/listings/ch03-common-programming-concepts/no-listing-21-function-return-values/Cargo.toml +++ b/listings/ch03-common-programming-concepts/no-listing-21-function-return-values/Cargo.toml @@ -1,7 +1,6 @@ [package] name = "functions" version = "0.1.0" -authors = ["Your Name "] edition = "2018" [dependencies] diff --git a/listings/ch03-common-programming-concepts/no-listing-22-function-parameter-and-return/Cargo.toml b/listings/ch03-common-programming-concepts/no-listing-22-function-parameter-and-return/Cargo.toml index 291680c..10f4053 100644 --- a/listings/ch03-common-programming-concepts/no-listing-22-function-parameter-and-return/Cargo.toml +++ b/listings/ch03-common-programming-concepts/no-listing-22-function-parameter-and-return/Cargo.toml @@ -1,7 +1,6 @@ [package] name = "functions" version = "0.1.0" -authors = ["Your Name "] edition = "2018" [dependencies] diff --git a/listings/ch03-common-programming-concepts/no-listing-23-statements-dont-return-values/Cargo.toml b/listings/ch03-common-programming-concepts/no-listing-23-statements-dont-return-values/Cargo.toml index 291680c..10f4053 100644 --- a/listings/ch03-common-programming-concepts/no-listing-23-statements-dont-return-values/Cargo.toml +++ b/listings/ch03-common-programming-concepts/no-listing-23-statements-dont-return-values/Cargo.toml @@ -1,7 +1,6 @@ [package] name = "functions" version = "0.1.0" -authors = ["Your Name "] edition = "2018" [dependencies] diff --git a/listings/ch03-common-programming-concepts/no-listing-23-statements-dont-return-values/output.txt b/listings/ch03-common-programming-concepts/no-listing-23-statements-dont-return-values/output.txt index 6657c63..4566ab7 100644 --- a/listings/ch03-common-programming-concepts/no-listing-23-statements-dont-return-values/output.txt +++ b/listings/ch03-common-programming-concepts/no-listing-23-statements-dont-return-values/output.txt @@ -10,9 +10,5 @@ error[E0308]: mismatched types 8 | x + 1; | - help: consider removing this semicolon -error: aborting due to previous error - For more information about this error, try `rustc --explain E0308`. -error: could not compile `functions` - -To learn more, run the command again with --verbose. +error: could not compile `functions` due to previous error diff --git a/listings/ch03-common-programming-concepts/no-listing-24-comments-end-of-line/Cargo.toml b/listings/ch03-common-programming-concepts/no-listing-24-comments-end-of-line/Cargo.toml index c53d875..614cbeb 100644 --- a/listings/ch03-common-programming-concepts/no-listing-24-comments-end-of-line/Cargo.toml +++ b/listings/ch03-common-programming-concepts/no-listing-24-comments-end-of-line/Cargo.toml @@ -1,7 +1,6 @@ [package] name = "comments" version = "0.1.0" -authors = ["Your Name "] edition = "2018" [dependencies] diff --git a/listings/ch03-common-programming-concepts/no-listing-24-comments-end-of-line/src/main.rs b/listings/ch03-common-programming-concepts/no-listing-24-comments-end-of-line/src/main.rs index 125ccca..535f4b9 100644 --- a/listings/ch03-common-programming-concepts/no-listing-24-comments-end-of-line/src/main.rs +++ b/listings/ch03-common-programming-concepts/no-listing-24-comments-end-of-line/src/main.rs @@ -1,3 +1,3 @@ fn main() { - let lucky_number = 7; // 我感觉今天好幸运 + let lucky_number = 7; // I’m feeling lucky today } diff --git a/listings/ch03-common-programming-concepts/no-listing-25-comments-above-line/Cargo.toml b/listings/ch03-common-programming-concepts/no-listing-25-comments-above-line/Cargo.toml index c53d875..614cbeb 100644 --- a/listings/ch03-common-programming-concepts/no-listing-25-comments-above-line/Cargo.toml +++ b/listings/ch03-common-programming-concepts/no-listing-25-comments-above-line/Cargo.toml @@ -1,7 +1,6 @@ [package] name = "comments" version = "0.1.0" -authors = ["Your Name "] edition = "2018" [dependencies] diff --git a/listings/ch03-common-programming-concepts/no-listing-25-comments-above-line/src/main.rs b/listings/ch03-common-programming-concepts/no-listing-25-comments-above-line/src/main.rs index 99581d7..81cd935 100644 --- a/listings/ch03-common-programming-concepts/no-listing-25-comments-above-line/src/main.rs +++ b/listings/ch03-common-programming-concepts/no-listing-25-comments-above-line/src/main.rs @@ -1,4 +1,4 @@ fn main() { - // 我感觉今天好幸运 + // I’m feeling lucky today let lucky_number = 7; } diff --git a/listings/ch03-common-programming-concepts/no-listing-26-if-true/Cargo.toml b/listings/ch03-common-programming-concepts/no-listing-26-if-true/Cargo.toml index 8ddf691..71c3f86 100644 --- a/listings/ch03-common-programming-concepts/no-listing-26-if-true/Cargo.toml +++ b/listings/ch03-common-programming-concepts/no-listing-26-if-true/Cargo.toml @@ -1,7 +1,6 @@ [package] name = "branches" version = "0.1.0" -authors = ["Your Name "] edition = "2018" [dependencies] diff --git a/listings/ch03-common-programming-concepts/no-listing-27-if-false/Cargo.toml b/listings/ch03-common-programming-concepts/no-listing-27-if-false/Cargo.toml index 8ddf691..71c3f86 100644 --- a/listings/ch03-common-programming-concepts/no-listing-27-if-false/Cargo.toml +++ b/listings/ch03-common-programming-concepts/no-listing-27-if-false/Cargo.toml @@ -1,7 +1,6 @@ [package] name = "branches" version = "0.1.0" -authors = ["Your Name "] edition = "2018" [dependencies] diff --git a/listings/ch03-common-programming-concepts/no-listing-28-if-condition-must-be-bool/Cargo.toml b/listings/ch03-common-programming-concepts/no-listing-28-if-condition-must-be-bool/Cargo.toml index 8ddf691..71c3f86 100644 --- a/listings/ch03-common-programming-concepts/no-listing-28-if-condition-must-be-bool/Cargo.toml +++ b/listings/ch03-common-programming-concepts/no-listing-28-if-condition-must-be-bool/Cargo.toml @@ -1,7 +1,6 @@ [package] name = "branches" version = "0.1.0" -authors = ["Your Name "] edition = "2018" [dependencies] diff --git a/listings/ch03-common-programming-concepts/no-listing-28-if-condition-must-be-bool/output.txt b/listings/ch03-common-programming-concepts/no-listing-28-if-condition-must-be-bool/output.txt index 5ddb737..735bfe7 100644 --- a/listings/ch03-common-programming-concepts/no-listing-28-if-condition-must-be-bool/output.txt +++ b/listings/ch03-common-programming-concepts/no-listing-28-if-condition-must-be-bool/output.txt @@ -6,9 +6,5 @@ error[E0308]: mismatched types 4 | if number { | ^^^^^^ expected `bool`, found integer -error: aborting due to previous error - For more information about this error, try `rustc --explain E0308`. -error: could not compile `branches` - -To learn more, run the command again with --verbose. +error: could not compile `branches` due to previous error diff --git a/listings/ch03-common-programming-concepts/no-listing-29-if-not-equal-0/Cargo.toml b/listings/ch03-common-programming-concepts/no-listing-29-if-not-equal-0/Cargo.toml index 8ddf691..71c3f86 100644 --- a/listings/ch03-common-programming-concepts/no-listing-29-if-not-equal-0/Cargo.toml +++ b/listings/ch03-common-programming-concepts/no-listing-29-if-not-equal-0/Cargo.toml @@ -1,7 +1,6 @@ [package] name = "branches" version = "0.1.0" -authors = ["Your Name "] edition = "2018" [dependencies] diff --git a/listings/ch03-common-programming-concepts/no-listing-30-else-if/Cargo.toml b/listings/ch03-common-programming-concepts/no-listing-30-else-if/Cargo.toml index 8ddf691..71c3f86 100644 --- a/listings/ch03-common-programming-concepts/no-listing-30-else-if/Cargo.toml +++ b/listings/ch03-common-programming-concepts/no-listing-30-else-if/Cargo.toml @@ -1,7 +1,6 @@ [package] name = "branches" version = "0.1.0" -authors = ["Your Name "] edition = "2018" [dependencies] diff --git a/listings/ch03-common-programming-concepts/no-listing-31-arms-must-return-same-type/Cargo.toml b/listings/ch03-common-programming-concepts/no-listing-31-arms-must-return-same-type/Cargo.toml index 8ddf691..71c3f86 100644 --- a/listings/ch03-common-programming-concepts/no-listing-31-arms-must-return-same-type/Cargo.toml +++ b/listings/ch03-common-programming-concepts/no-listing-31-arms-must-return-same-type/Cargo.toml @@ -1,7 +1,6 @@ [package] name = "branches" version = "0.1.0" -authors = ["Your Name "] edition = "2018" [dependencies] diff --git a/listings/ch03-common-programming-concepts/no-listing-31-arms-must-return-same-type/output.txt b/listings/ch03-common-programming-concepts/no-listing-31-arms-must-return-same-type/output.txt index 90934b6..e922acd 100644 --- a/listings/ch03-common-programming-concepts/no-listing-31-arms-must-return-same-type/output.txt +++ b/listings/ch03-common-programming-concepts/no-listing-31-arms-must-return-same-type/output.txt @@ -8,9 +8,5 @@ error[E0308]: `if` and `else` have incompatible types | | | expected because of this -error: aborting due to previous error - For more information about this error, try `rustc --explain E0308`. -error: could not compile `branches` - -To learn more, run the command again with --verbose. +error: could not compile `branches` due to previous error diff --git a/listings/ch03-common-programming-concepts/no-listing-32-5-loop-labels/Cargo.lock b/listings/ch03-common-programming-concepts/no-listing-32-5-loop-labels/Cargo.lock new file mode 100644 index 0000000..f738673 --- /dev/null +++ b/listings/ch03-common-programming-concepts/no-listing-32-5-loop-labels/Cargo.lock @@ -0,0 +1,5 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +[[package]] +name = "loops" +version = "0.1.0" diff --git a/listings/ch03-common-programming-concepts/no-listing-32-5-loop-labels/Cargo.toml b/listings/ch03-common-programming-concepts/no-listing-32-5-loop-labels/Cargo.toml new file mode 100644 index 0000000..9a198d7 --- /dev/null +++ b/listings/ch03-common-programming-concepts/no-listing-32-5-loop-labels/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "loops" +version = "0.1.0" +edition = "2018" + +[dependencies] diff --git a/listings/ch03-common-programming-concepts/no-listing-32-5-loop-labels/output.txt b/listings/ch03-common-programming-concepts/no-listing-32-5-loop-labels/output.txt new file mode 100644 index 0000000..d4d322f --- /dev/null +++ b/listings/ch03-common-programming-concepts/no-listing-32-5-loop-labels/output.txt @@ -0,0 +1,13 @@ +$ cargo run + Compiling loops v0.1.0 (file:///projects/loops) + Finished dev [unoptimized + debuginfo] target(s) in 0.58s + Running `target/debug/loops` +count = 0 +remaining = 10 +remaining = 9 +count = 1 +remaining = 10 +remaining = 9 +count = 2 +remaining = 10 +End count = 2 diff --git a/listings/ch03-common-programming-concepts/no-listing-32-5-loop-labels/src/main.rs b/listings/ch03-common-programming-concepts/no-listing-32-5-loop-labels/src/main.rs new file mode 100644 index 0000000..b855d75 --- /dev/null +++ b/listings/ch03-common-programming-concepts/no-listing-32-5-loop-labels/src/main.rs @@ -0,0 +1,21 @@ +fn main() { + let mut count = 0; + 'counting_up: loop { + println!("count = {}", count); + let mut remaining = 10; + + loop { + println!("remaining = {}", remaining); + if remaining == 9 { + break; + } + if count == 2 { + break 'counting_up; + } + remaining -= 1; + } + + count += 1; + } + println!("End count = {}", count); +} diff --git a/listings/ch03-common-programming-concepts/no-listing-32-loop/Cargo.toml b/listings/ch03-common-programming-concepts/no-listing-32-loop/Cargo.toml index b5ed848..9a198d7 100644 --- a/listings/ch03-common-programming-concepts/no-listing-32-loop/Cargo.toml +++ b/listings/ch03-common-programming-concepts/no-listing-32-loop/Cargo.toml @@ -1,7 +1,6 @@ [package] name = "loops" version = "0.1.0" -authors = ["Your Name "] edition = "2018" [dependencies] diff --git a/listings/ch03-common-programming-concepts/no-listing-33-return-value-from-loop/Cargo.toml b/listings/ch03-common-programming-concepts/no-listing-33-return-value-from-loop/Cargo.toml index b5ed848..9a198d7 100644 --- a/listings/ch03-common-programming-concepts/no-listing-33-return-value-from-loop/Cargo.toml +++ b/listings/ch03-common-programming-concepts/no-listing-33-return-value-from-loop/Cargo.toml @@ -1,7 +1,6 @@ [package] name = "loops" version = "0.1.0" -authors = ["Your Name "] edition = "2018" [dependencies] diff --git a/listings/ch03-common-programming-concepts/no-listing-34-for-range/Cargo.toml b/listings/ch03-common-programming-concepts/no-listing-34-for-range/Cargo.toml index b5ed848..9a198d7 100644 --- a/listings/ch03-common-programming-concepts/no-listing-34-for-range/Cargo.toml +++ b/listings/ch03-common-programming-concepts/no-listing-34-for-range/Cargo.toml @@ -1,7 +1,6 @@ [package] name = "loops" version = "0.1.0" -authors = ["Your Name "] edition = "2018" [dependencies] diff --git a/listings/ch03-common-programming-concepts/output-only-01-no-type-annotations/Cargo.toml b/listings/ch03-common-programming-concepts/output-only-01-no-type-annotations/Cargo.toml index 964f9e8..b263d5b 100644 --- a/listings/ch03-common-programming-concepts/output-only-01-no-type-annotations/Cargo.toml +++ b/listings/ch03-common-programming-concepts/output-only-01-no-type-annotations/Cargo.toml @@ -1,7 +1,6 @@ [package] name = "no_type_annotations" version = "0.1.0" -authors = ["Your Name "] edition = "2018" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/listings/ch03-common-programming-concepts/output-only-01-no-type-annotations/output.txt b/listings/ch03-common-programming-concepts/output-only-01-no-type-annotations/output.txt index df0ed35..d9807ce 100644 --- a/listings/ch03-common-programming-concepts/output-only-01-no-type-annotations/output.txt +++ b/listings/ch03-common-programming-concepts/output-only-01-no-type-annotations/output.txt @@ -6,9 +6,5 @@ error[E0282]: type annotations needed 2 | let guess = "42".parse().expect("Not a number!"); | ^^^^^ consider giving `guess` a type -error: aborting due to previous error - For more information about this error, try `rustc --explain E0282`. -error: could not compile `no_type_annotations` - -To learn more, run the command again with --verbose. +error: could not compile `no_type_annotations` due to previous error