Update listing code in ch03

Signed-off-by: Sefank <12670778+Sefank@users.noreply.github.com>
pull/624/head
Sefank 2 years ago
parent 860f99a134
commit 7090f728ec
No known key found for this signature in database
GPG Key ID: 8257999DC508E901

@ -2,5 +2,5 @@ fn main() {
let condition = true; let condition = true;
let number = if condition { 5 } else { 6 }; let number = if condition { 5 } else { 6 };
println!("The value of number is: {}", number); println!("The value of number is: {number}");
} }

@ -2,7 +2,7 @@ fn main() {
let mut number = 3; let mut number = 3;
while number != 0 { while number != 0 {
println!("{}!", number); println!("{number}!");
number -= 1; number -= 1;
} }

@ -2,6 +2,6 @@ fn main() {
let a = [10, 20, 30, 40, 50]; let a = [10, 20, 30, 40, 50];
for element in a { for element in a {
println!("the value is: {}", element); println!("the value is: {element}");
} }
} }

@ -8,7 +8,7 @@ error[E0384]: cannot assign twice to immutable variable `x`
| | | |
| first assignment to `x` | first assignment to `x`
| help: consider making this binding mutable: `mut 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; 4 | x = 6;
| ^^^^^ cannot assign twice to immutable variable | ^^^^^ cannot assign twice to immutable variable

@ -1,6 +1,6 @@
fn main() { fn main() {
let x = 5; let x = 5;
println!("The value of x is: {}", x); println!("The value of x is: {x}");
x = 6; x = 6;
println!("The value of x is: {}", x); println!("The value of x is: {x}");
} }

@ -1,6 +1,6 @@
fn main() { fn main() {
let mut x = 5; let mut x = 5;
println!("The value of x is: {}", x); println!("The value of x is: {x}");
x = 6; x = 6;
println!("The value of x is: {}", x); println!("The value of x is: {x}");
} }

@ -5,8 +5,8 @@ fn main() {
{ {
let x = x * 2; 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}");
} }

@ -1,17 +1,17 @@
fn main() { fn main() {
// 加法 // addition
let sum = 5 + 10; let sum = 5 + 10;
// 减法 // subtraction
let difference = 95.5 - 4.3; let difference = 95.5 - 4.3;
// 乘法 // multiplication
let product = 4 * 30; let product = 4 * 30;
// 除法 // division
let quotient = 56.7 / 32.2; let quotient = 56.7 / 32.2;
let floored = 2 / 3; // 结果为 0 let floored = 2 / 3; // Results in 0
// 取余 // remainder
let remainder = 43 % 5; let remainder = 43 % 5;
} }

@ -1,5 +1,5 @@
fn main() { fn main() {
let t = true; let t = true;
let f: bool = false; // 显式指定类型注解 let f: bool = false; // with explicit type annotation
} }

@ -1,5 +1,5 @@
fn main() { fn main() {
let c = 'z'; let c = 'z';
let z = ''; let z: char = ''; // with explicit type annotation
let heart_eyed_cat = '😻'; let heart_eyed_cat = '😻';
} }

@ -3,5 +3,5 @@ fn main() {
let (x, y, z) = tup; let (x, y, z) = tup;
println!("The value of y is: {}", y); println!("The value of y is: {y}");
} }

@ -18,8 +18,5 @@ fn main() {
let element = a[index]; let element = a[index];
println!( println!("The value of the element at index {index} is: {element}");
"The value of the element at index {} is: {}",
index, element
);
} }

@ -3,5 +3,5 @@ fn main() {
} }
fn another_function(x: i32) { fn another_function(x: i32) {
println!("The value of x is: {}", x); println!("The value of x is: {x}");
} }

@ -3,5 +3,5 @@ fn main() {
} }
fn print_labeled_measurement(value: i32, unit_label: char) { fn print_labeled_measurement(value: i32, unit_label: char) {
println!("The measurement is: {}{}", value, unit_label); println!("The measurement is: {value}{unit_label}");
} }

@ -8,14 +8,13 @@ error: expected expression, found statement (`let`)
| |
= note: variable declaration using `let` is a statement = 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 --> src/main.rs:2:14
| |
2 | let x = (let y = 6); 2 | let x = (let y = 6);
| ^^^^^^^^^ | ^^^^^^^^^
| |
= note: see issue #53667 <https://github.com/rust-lang/rust/issues/53667> for more information = note: see issue #53667 <https://github.com/rust-lang/rust/issues/53667> for more information
= help: you can write `matches!(<expr>, <pattern>)` instead of `let <pattern> = <expr>`
warning: unnecessary parentheses around assigned value warning: unnecessary parentheses around assigned value
--> src/main.rs:2:13 --> src/main.rs:2:13

@ -4,5 +4,5 @@ fn main() {
x + 1 x + 1
}; };
println!("The value of y is: {}", y); println!("The value of y is: {y}");
} }

@ -5,5 +5,5 @@ fn five() -> i32 {
fn main() { fn main() {
let x = five(); let x = five();
println!("The value of x is: {}", x); println!("The value of x is: {x}");
} }

@ -1,7 +1,7 @@
fn main() { fn main() {
let x = plus_one(5); 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 { fn plus_one(x: i32) -> i32 {

@ -1,7 +1,7 @@
fn main() { fn main() {
let x = plus_one(5); 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 { fn plus_one(x: i32) -> i32 {

@ -3,5 +3,5 @@ fn main() {
let number = if condition { 5 } else { "six" }; let number = if condition { 5 } else { "six" };
println!("The value of number is: {}", number); println!("The value of number is: {number}");
} }

@ -1,11 +1,11 @@
fn main() { fn main() {
let mut count = 0; let mut count = 0;
'counting_up: loop { 'counting_up: loop {
println!("count = {}", count); println!("count = {count}");
let mut remaining = 10; let mut remaining = 10;
loop { loop {
println!("remaining = {}", remaining); println!("remaining = {remaining}");
if remaining == 9 { if remaining == 9 {
break; break;
} }
@ -17,5 +17,5 @@ fn main() {
count += 1; count += 1;
} }
println!("End count = {}", count); println!("End count = {count}");
} }

@ -9,5 +9,5 @@ fn main() {
} }
}; };
println!("The result is {}", result); println!("The result is {result}");
} }

@ -1,6 +1,6 @@
fn main() { fn main() {
for number in (1..4).rev() { for number in (1..4).rev() {
println!("{}!", number); println!("{number}!");
} }
println!("LIFTOFF!!!"); println!("LIFTOFF!!!");
} }

Loading…
Cancel
Save