Skip to content

Commit 49f93be

Browse files
committed
ch03 一般的なプログラミングの概念の和訳を最新版に更新
rust-lang/book@19c40bf
1 parent cc34c09 commit 49f93be

File tree

33 files changed

+787
-589
lines changed

33 files changed

+787
-589
lines changed

listings/ch03-common-programming-concepts/listing-03-02/src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ fn main() {
22
let condition = true;
33
let number = if condition { 5 } else { 6 };
44

5-
// numberの値は、{}です
6-
println!("The value of number is: {}", number);
5+
// numberの値は、{number}です
6+
println!("The value of number is: {number}");
77
}

listings/ch03-common-programming-concepts/listing-03-03/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ fn main() {
22
let mut number = 3;
33

44
while number != 0 {
5-
println!("{}!", number);
5+
println!("{number}!");
66

77
number -= 1;
88
}

listings/ch03-common-programming-concepts/listing-03-05/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ fn main() {
22
let a = [10, 20, 30, 40, 50];
33

44
for element in a {
5-
println!("the value is: {}", element);
5+
println!("the value is: {element}");
66
}
77
}

listings/ch03-common-programming-concepts/no-listing-01-variables-are-immutable/output.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ error[E0384]: cannot assign twice to immutable variable `x`
1010
| first assignment to `x`
1111
| (`x`への最初の代入)
1212
| help: consider making this binding mutable: `mut x`
13-
3 | println!("The value of x is: {}", x);
13+
3 | println!("The value of x is: {x}");
1414
4 | x = 6;
1515
| ^^^^^ cannot assign twice to immutable variable
1616

1717
For more information about this error, try `rustc --explain E0384`.
18-
error: could not compile `variables` due to previous error
18+
error: could not compile `variables` (bin "variables") due to 1 previous error
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
fn main() {
22
let x = 5;
3-
println!("The value of x is: {}", x); // xの値は{}です
3+
println!("The value of x is: {x}"); // xの値は{x}です
44
x = 6;
5-
println!("The value of x is: {}", x);
5+
println!("The value of x is: {x}");
66
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
fn main() {
22
let mut x = 5;
3-
println!("The value of x is: {}", x);
3+
println!("The value of x is: {x}");
44
x = 6;
5-
println!("The value of x is: {}", x);
5+
println!("The value of x is: {x}");
66
}

listings/ch03-common-programming-concepts/no-listing-03-shadowing/src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ fn main() {
55

66
{
77
let x = x * 2;
8-
println!("The value of x in the inner scope is: {}", x);
8+
println!("The value of x in the inner scope is: {x}");
99
}
1010

11-
println!("The value of x is: {}", x);
11+
println!("The value of x is: {x}");
1212
}

listings/ch03-common-programming-concepts/no-listing-05-mut-cant-change-types/output.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ error[E0308]: mismatched types (型が合いません)
88
3 | spaces = spaces.len();
99
| ^^^^^^^^^^^^ expected `&str`, found `usize`
1010
| (&str型を予期しましたが、usizeが見つかりました)
11+
|
12+
help: try removing the method call
13+
|
14+
3 - spaces = spaces.len();
15+
3 + spaces = spaces;
16+
|
1117

1218
For more information about this error, try `rustc --explain E0308`.
13-
error: could not compile `variables` due to previous error
19+
error: could not compile `variables` (bin "variables") due to 1 previous error

listings/ch03-common-programming-concepts/no-listing-07-numeric-operations/src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ fn main() {
1414
// division
1515
// 割り算
1616
let quotient = 56.7 / 32.2;
17-
let floored = 2 / 3; // Results in 0
18-
// 結果は0
17+
let truncated = -5 / 3; // Results in -1
18+
// 結果は-1
1919

2020
// remainder
2121
// 余り
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
fn main() {
22
let c = 'z';
3-
let z = 'ℤ';
3+
let z: char = 'ℤ'; // with explicit type annotation
4+
// 明示的型注釈付きで
45
let heart_eyed_cat = '😻'; //ハート目の猫
56
}

0 commit comments

Comments
 (0)