diff --git a/listings/ch03-common-programming-concepts/listing-03-02/src/main.rs b/listings/ch03-common-programming-concepts/listing-03-02/src/main.rs index 0b8ee95..e021e41 100755 --- a/listings/ch03-common-programming-concepts/listing-03-02/src/main.rs +++ b/listings/ch03-common-programming-concepts/listing-03-02/src/main.rs @@ -2,5 +2,5 @@ fn main() { let condition = true; let number = if condition { 5 } else { 6 }; - println!("The value of number is: {}", number); + println!("The value of number is: {number}"); } diff --git a/listings/ch03-common-programming-concepts/listing-03-03/src/main.rs b/listings/ch03-common-programming-concepts/listing-03-03/src/main.rs index 651ed68..ca070c7 100755 --- a/listings/ch03-common-programming-concepts/listing-03-03/src/main.rs +++ b/listings/ch03-common-programming-concepts/listing-03-03/src/main.rs @@ -2,7 +2,7 @@ fn main() { let mut number = 3; while number != 0 { - println!("{}!", number); + println!("{number}!"); number -= 1; } 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 5eaa7a0..b44e6b7 100755 --- a/listings/ch03-common-programming-concepts/listing-03-05/src/main.rs +++ b/listings/ch03-common-programming-concepts/listing-03-05/src/main.rs @@ -2,6 +2,6 @@ fn main() { let a = [10, 20, 30, 40, 50]; for element in a { - println!("the value is: {}", element); + println!("the value is: {element}"); } } 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 2b7e562..ed87cb2 100755 --- 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 @@ -8,7 +8,7 @@ error[E0384]: cannot assign twice to immutable variable `x` | | | first assignment to `x` | help: consider making this binding mutable: `mut x` -3 | println!("The value of x is: {}", x); +3 | println!("The value of x is: {x}"); 4 | x = 6; | ^^^^^ cannot assign twice to immutable variable diff --git a/listings/ch03-common-programming-concepts/no-listing-01-variables-are-immutable/src/main.rs b/listings/ch03-common-programming-concepts/no-listing-01-variables-are-immutable/src/main.rs index a6c7ac0..d64f46d 100755 --- a/listings/ch03-common-programming-concepts/no-listing-01-variables-are-immutable/src/main.rs +++ b/listings/ch03-common-programming-concepts/no-listing-01-variables-are-immutable/src/main.rs @@ -1,6 +1,6 @@ fn main() { let x = 5; - println!("The value of x is: {}", x); + println!("The value of x is: {x}"); x = 6; - println!("The value of x is: {}", x); + println!("The value of x is: {x}"); } diff --git a/listings/ch03-common-programming-concepts/no-listing-02-adding-mut/src/main.rs b/listings/ch03-common-programming-concepts/no-listing-02-adding-mut/src/main.rs index c4e4a19..a57709c 100755 --- a/listings/ch03-common-programming-concepts/no-listing-02-adding-mut/src/main.rs +++ b/listings/ch03-common-programming-concepts/no-listing-02-adding-mut/src/main.rs @@ -1,6 +1,6 @@ fn main() { let mut x = 5; - println!("The value of x is: {}", x); + println!("The value of x is: {x}"); x = 6; - println!("The value of x is: {}", x); + println!("The value of x is: {x}"); } 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 606ee68..03924fe 100755 --- 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 @@ -5,8 +5,8 @@ fn main() { { let x = x * 2; - println!("The value of x in the inner scope is: {}", x); + println!("The value of x in the inner scope is: {x}"); } - println!("The value of x is: {}", x); + println!("The value of x is: {x}"); } 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 1bc8dac..9d3b481 100755 --- 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 @@ -1,17 +1,17 @@ fn main() { - // 加法 + // addition let sum = 5 + 10; - // 减法 + // subtraction let difference = 95.5 - 4.3; - // 乘法 + // multiplication let product = 4 * 30; - // 除法 + // division let quotient = 56.7 / 32.2; - let floored = 2 / 3; // 结果为 0 + let floored = 2 / 3; // Results in 0 - // 取余 + // remainder let remainder = 43 % 5; } 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 d004d9f..2c56e62 100755 --- 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/src/main.rs b/listings/ch03-common-programming-concepts/no-listing-09-char/src/main.rs index 4b8d9d9..4921cc9 100755 --- a/listings/ch03-common-programming-concepts/no-listing-09-char/src/main.rs +++ b/listings/ch03-common-programming-concepts/no-listing-09-char/src/main.rs @@ -1,5 +1,5 @@ fn main() { let c = 'z'; - let z = 'ℤ'; + let z: char = 'ℤ'; // with explicit type annotation let heart_eyed_cat = '😻'; } diff --git a/listings/ch03-common-programming-concepts/no-listing-11-destructuring-tuples/src/main.rs b/listings/ch03-common-programming-concepts/no-listing-11-destructuring-tuples/src/main.rs index 35dcb44..3002bdd 100755 --- a/listings/ch03-common-programming-concepts/no-listing-11-destructuring-tuples/src/main.rs +++ b/listings/ch03-common-programming-concepts/no-listing-11-destructuring-tuples/src/main.rs @@ -3,5 +3,5 @@ fn main() { let (x, y, z) = tup; - println!("The value of y is: {}", y); + println!("The value of y is: {y}"); } diff --git a/listings/ch03-common-programming-concepts/no-listing-15-invalid-array-access/src/main.rs b/listings/ch03-common-programming-concepts/no-listing-15-invalid-array-access/src/main.rs index 5e51216..b634c93 100755 --- a/listings/ch03-common-programming-concepts/no-listing-15-invalid-array-access/src/main.rs +++ b/listings/ch03-common-programming-concepts/no-listing-15-invalid-array-access/src/main.rs @@ -18,8 +18,5 @@ fn main() { let element = a[index]; - println!( - "The value of the element at index {} is: {}", - index, element - ); + println!("The value of the element at index {index} is: {element}"); } diff --git a/listings/ch03-common-programming-concepts/no-listing-17-functions-with-parameters/src/main.rs b/listings/ch03-common-programming-concepts/no-listing-17-functions-with-parameters/src/main.rs index 029446c..108da4f 100755 --- a/listings/ch03-common-programming-concepts/no-listing-17-functions-with-parameters/src/main.rs +++ b/listings/ch03-common-programming-concepts/no-listing-17-functions-with-parameters/src/main.rs @@ -3,5 +3,5 @@ fn main() { } fn another_function(x: i32) { - println!("The value of x is: {}", x); + println!("The value of x is: {x}"); } 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 543c2ea..b070ccb 100755 --- 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 @@ -3,5 +3,5 @@ fn main() { } fn print_labeled_measurement(value: i32, unit_label: char) { - println!("The measurement is: {}{}", value, unit_label); + println!("The measurement is: {value}{unit_label}"); } 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 b33f8bd..a5a85f4 100755 --- 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 @@ -8,14 +8,13 @@ error: expected expression, found statement (`let`) | = note: variable declaration using `let` is a statement -error[E0658]: `let` expressions in this position are experimental +error[E0658]: `let` expressions in this position are unstable --> src/main.rs:2:14 | 2 | let x = (let y = 6); | ^^^^^^^^^ | = note: see issue #53667 for more information - = help: you can write `matches!(, )` instead of `let = ` warning: unnecessary parentheses around assigned value --> src/main.rs:2:13 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 0be7fcb..64b8732 100755 --- 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 @@ -4,5 +4,5 @@ fn main() { x + 1 }; - println!("The value of y is: {}", y); + println!("The value of y is: {y}"); } diff --git a/listings/ch03-common-programming-concepts/no-listing-21-function-return-values/src/main.rs b/listings/ch03-common-programming-concepts/no-listing-21-function-return-values/src/main.rs index 5303b10..a11af7e 100755 --- a/listings/ch03-common-programming-concepts/no-listing-21-function-return-values/src/main.rs +++ b/listings/ch03-common-programming-concepts/no-listing-21-function-return-values/src/main.rs @@ -5,5 +5,5 @@ fn five() -> i32 { fn main() { let x = five(); - println!("The value of x is: {}", x); + println!("The value of x is: {x}"); } diff --git a/listings/ch03-common-programming-concepts/no-listing-22-function-parameter-and-return/src/main.rs b/listings/ch03-common-programming-concepts/no-listing-22-function-parameter-and-return/src/main.rs index b4c8443..da9d0dd 100755 --- a/listings/ch03-common-programming-concepts/no-listing-22-function-parameter-and-return/src/main.rs +++ b/listings/ch03-common-programming-concepts/no-listing-22-function-parameter-and-return/src/main.rs @@ -1,7 +1,7 @@ fn main() { let x = plus_one(5); - println!("The value of x is: {}", x); + println!("The value of x is: {x}"); } fn plus_one(x: i32) -> i32 { diff --git a/listings/ch03-common-programming-concepts/no-listing-23-statements-dont-return-values/src/main.rs b/listings/ch03-common-programming-concepts/no-listing-23-statements-dont-return-values/src/main.rs index c9c4edc..1cec800 100755 --- a/listings/ch03-common-programming-concepts/no-listing-23-statements-dont-return-values/src/main.rs +++ b/listings/ch03-common-programming-concepts/no-listing-23-statements-dont-return-values/src/main.rs @@ -1,7 +1,7 @@ fn main() { let x = plus_one(5); - println!("The value of x is: {}", x); + println!("The value of x is: {x}"); } fn plus_one(x: i32) -> i32 { diff --git a/listings/ch03-common-programming-concepts/no-listing-31-arms-must-return-same-type/src/main.rs b/listings/ch03-common-programming-concepts/no-listing-31-arms-must-return-same-type/src/main.rs index 440b286..df7068b 100755 --- a/listings/ch03-common-programming-concepts/no-listing-31-arms-must-return-same-type/src/main.rs +++ b/listings/ch03-common-programming-concepts/no-listing-31-arms-must-return-same-type/src/main.rs @@ -3,5 +3,5 @@ fn main() { let number = if condition { 5 } else { "six" }; - println!("The value of number is: {}", number); + println!("The value of number is: {number}"); } 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 index b855d75..dd88564 100755 --- 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 @@ -1,11 +1,11 @@ fn main() { let mut count = 0; 'counting_up: loop { - println!("count = {}", count); + println!("count = {count}"); let mut remaining = 10; loop { - println!("remaining = {}", remaining); + println!("remaining = {remaining}"); if remaining == 9 { break; } @@ -17,5 +17,5 @@ fn main() { count += 1; } - println!("End count = {}", count); + println!("End count = {count}"); } diff --git a/listings/ch03-common-programming-concepts/no-listing-33-return-value-from-loop/src/main.rs b/listings/ch03-common-programming-concepts/no-listing-33-return-value-from-loop/src/main.rs index 6ffdab5..683d18b 100755 --- a/listings/ch03-common-programming-concepts/no-listing-33-return-value-from-loop/src/main.rs +++ b/listings/ch03-common-programming-concepts/no-listing-33-return-value-from-loop/src/main.rs @@ -9,5 +9,5 @@ fn main() { } }; - println!("The result is {}", result); + println!("The result is {result}"); } diff --git a/listings/ch03-common-programming-concepts/no-listing-34-for-range/src/main.rs b/listings/ch03-common-programming-concepts/no-listing-34-for-range/src/main.rs index e7286a8..df5b305 100755 --- a/listings/ch03-common-programming-concepts/no-listing-34-for-range/src/main.rs +++ b/listings/ch03-common-programming-concepts/no-listing-34-for-range/src/main.rs @@ -1,6 +1,6 @@ fn main() { for number in (1..4).rev() { - println!("{}!", number); + println!("{number}!"); } println!("LIFTOFF!!!"); }