Skip to content

Commit

Permalink
Update listing code in ch03
Browse files Browse the repository at this point in the history
Signed-off-by: Sefank <[email protected]>
  • Loading branch information
Sefank committed Jul 4, 2022
1 parent 860f99a commit 7090f72
Show file tree
Hide file tree
Showing 23 changed files with 33 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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}");
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ fn main() {
let mut number = 3;

while number != 0 {
println!("{}!", number);
println!("{number}!");

number -= 1;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
@@ -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}");
}
Original file line number Diff line number Diff line change
@@ -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}");
}
Original file line number Diff line number Diff line change
Expand Up @@ -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}");
}
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
fn main() {
let t = true;

let f: bool = false; // 显式指定类型注解
let f: bool = false; // with explicit type annotation
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
fn main() {
let c = 'z';
let z = 'ℤ';
let z: char = 'ℤ'; // with explicit type annotation
let heart_eyed_cat = '😻';
}
Original file line number Diff line number Diff line change
Expand Up @@ -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}");
}
Original file line number Diff line number Diff line change
Expand Up @@ -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}");
}
Original file line number Diff line number Diff line change
Expand Up @@ -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}");
}
Original file line number Diff line number Diff line change
Expand Up @@ -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}");
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 <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
--> src/main.rs:2:13
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ fn main() {
x + 1
};

println!("The value of y is: {}", y);
println!("The value of y is: {y}");
}
Original file line number Diff line number Diff line change
Expand Up @@ -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}");
}
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}");
}
Original file line number Diff line number Diff line change
@@ -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;
}
Expand All @@ -17,5 +17,5 @@ fn main() {

count += 1;
}
println!("End count = {}", count);
println!("End count = {count}");
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ fn main() {
}
};

println!("The result is {}", result);
println!("The result is {result}");
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
fn main() {
for number in (1..4).rev() {
println!("{}!", number);
println!("{number}!");
}
println!("LIFTOFF!!!");
}

0 comments on commit 7090f72

Please sign in to comment.