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

+2-2
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

+1-1
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

+1-1
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

+2-2
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
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
}
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

+2-2
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

+7-1
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

+2-2
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
// 余り
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
}

listings/ch03-common-programming-concepts/no-listing-11-destructuring-tuples/src/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ fn main() {
33

44
let (x, y, z) = tup;
55

6-
println!("The value of y is: {}", y);
6+
println!("The value of y is: {y}");
77
}

listings/ch03-common-programming-concepts/no-listing-15-invalid-array-access/src/main.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@ fn main() {
2121

2222
let element = a[index];
2323

24-
println!(
25-
"The value of the element at index {} is: {}",
26-
// {}番目の要素の値は{}です
27-
index, element
28-
);
24+
println!("The value of the element at index {index} is: {element}");
25+
// {index}番目の要素の値は{element}です
2926
}

listings/ch03-common-programming-concepts/no-listing-17-functions-with-parameters/src/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ fn main() {
33
}
44

55
fn another_function(x: i32) {
6-
println!("The value of x is: {}", x); // xの値は{}です
6+
println!("The value of x is: {x}"); // xの値は{x}です
77
}

listings/ch03-common-programming-concepts/no-listing-18-functions-with-multiple-parameters/src/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ fn main() {
33
}
44

55
fn print_labeled_measurement(value: i32, unit_label: char) {
6-
println!("The measurement is: {}{}", value, unit_label);
6+
println!("The measurement is: {value}{unit_label}");
77
}
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,14 @@
11
$ cargo run
22
Compiling functions v0.1.0 (file:///projects/functions)
3-
error: expected expression, found statement (`let`)
4-
(エラー: 式を予期しましたが、文が見つかりました (`let`))
3+
error: expected expression, found `let` statement
4+
(エラー: 式を予期しましたが、`let`文が見つかりました)
55
--> src/main.rs:2:14
66
|
77
2 | let x = (let y = 6);
8-
| ^^^^^^^^^
8+
| ^^^
99
|
10-
= note: variable declaration using `let` is a statement
11-
(注釈: `let`を使う変数宣言は、文です)
12-
13-
error[E0658]: `let` expressions in this position are experimental
14-
--> src/main.rs:2:14
15-
|
16-
2 | let x = (let y = 6);
17-
| ^^^^^^^^^
18-
|
19-
= note: see issue #53667 <https://github.com/rust-lang/rust/issues/53667> for more information
20-
= help: you can write `matches!(<expr>, <pattern>)` instead of `let <pattern> = <expr>`
10+
= note: only supported directly in conditions of `if` and `while` expressions
11+
(注釈: `if` および `while` 式の条件部直下でのみ対応しています
2112

2213
warning: unnecessary parentheses around assigned value
2314
--> src/main.rs:2:13
@@ -30,8 +21,7 @@ help: remove these parentheses
3021
|
3122
2 - let x = (let y = 6);
3223
2 + let x = let y = 6;
33-
|
24+
|
3425

35-
For more information about this error, try `rustc --explain E0658`.
3626
warning: `functions` (bin "functions") generated 1 warning
37-
error: could not compile `functions` due to 2 previous errors; 1 warning emitted
27+
error: could not compile `functions` (bin "functions") due to 1 previous error; 1 warning emitted

listings/ch03-common-programming-concepts/no-listing-20-blocks-are-expressions/src/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ fn main() {
44
x + 1
55
};
66

7-
println!("The value of y is: {}", y);
7+
println!("The value of y is: {y}");
88
}

listings/ch03-common-programming-concepts/no-listing-21-function-return-values/src/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ fn five() -> i32 {
55
fn main() {
66
let x = five();
77

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

listings/ch03-common-programming-concepts/no-listing-22-function-parameter-and-return/src/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
fn main() {
22
let x = plus_one(5);
33

4-
println!("The value of x is: {}", x);
4+
println!("The value of x is: {x}");
55
}
66

77
fn plus_one(x: i32) -> i32 {

listings/ch03-common-programming-concepts/no-listing-23-statements-dont-return-values/output.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ error[E0308]: mismatched types
99
| |
1010
| implicitly returns `()` as its body has no tail or `return` expression
1111
8 | x + 1;
12-
| - help: consider removing this semicolon
12+
| - help: remove this semicolon to return this value
1313

1414
For more information about this error, try `rustc --explain E0308`.
15-
error: could not compile `functions` due to previous error
15+
error: could not compile `functions` (bin "functions") due to 1 previous error

listings/ch03-common-programming-concepts/no-listing-23-statements-dont-return-values/src/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
fn main() {
22
let x = plus_one(5);
33

4-
println!("The value of x is: {}", x);
4+
println!("The value of x is: {x}");
55
}
66

77
fn plus_one(x: i32) -> i32 {

listings/ch03-common-programming-concepts/no-listing-28-if-condition-must-be-bool/output.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ error[E0308]: mismatched types
99
| (bool型を予期したのに、整数変数が見つかりました)
1010

1111
For more information about this error, try `rustc --explain E0308`.
12-
error: could not compile `branches` due to previous error
12+
error: could not compile `branches` (bin "branches") due to 1 previous error

listings/ch03-common-programming-concepts/no-listing-31-arms-must-return-same-type/output.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ error[E0308]: `if` and `else` have incompatible types
1111
| expected because of this
1212

1313
For more information about this error, try `rustc --explain E0308`.
14-
error: could not compile `branches` due to previous error
14+
error: could not compile `branches` (bin "branches") due to 1 previous error

listings/ch03-common-programming-concepts/no-listing-31-arms-must-return-same-type/src/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ fn main() {
33

44
let number = if condition { 5 } else { "six" };
55

6-
println!("The value of number is: {}", number);
6+
println!("The value of number is: {number}");
77
}

listings/ch03-common-programming-concepts/no-listing-32-5-loop-labels/src/main.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
fn main() {
22
let mut count = 0;
33
'counting_up: loop {
4-
println!("count = {}", count);
4+
println!("count = {count}");
55
let mut remaining = 10;
66

77
loop {
8-
println!("remaining = {}", remaining);
8+
println!("remaining = {remaining}");
99
if remaining == 9 {
1010
break;
1111
}
@@ -17,5 +17,5 @@ fn main() {
1717

1818
count += 1;
1919
}
20-
println!("End count = {}", count);
20+
println!("End count = {count}");
2121
}

listings/ch03-common-programming-concepts/no-listing-33-return-value-from-loop/src/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@ fn main() {
99
}
1010
};
1111

12-
println!("The result is {}", result);
12+
println!("The result is {result}");
1313
}
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
fn main() {
22
for number in (1..4).rev() {
3-
println!("{}!", number);
3+
println!("{number}!");
44
}
55
println!("LIFTOFF!!!");
66
}
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
11
$ cargo build
22
Compiling no_type_annotations v0.1.0 (file:///projects/no_type_annotations)
3-
error[E0282]: type annotations needed
3+
error[E0284]: type annotations needed
44
(型注釈が必要です)
55
--> src/main.rs:2:9
66
|
77
2 | let guess = "42".parse().expect("Not a number!");
8-
| ^^^^^ consider giving `guess` a type
9-
| (`guess`に型を与えることを検討してください)
8+
| ^^^^^ ----- type must be known at this point
9+
| (型はこの時点で既知でなくてはなりません)
10+
|
11+
= note: cannot satisfy `<_ as FromStr>::Err == _`
12+
(`<_ as FromStr>::Err == _`を満たすことができません)
13+
help: consider giving `guess` an explicit type
14+
| (`guess`に型を与えることを検討してください)
15+
|
16+
2 | let guess: /* Type */ = "42".parse().expect("Not a number!");
17+
| ++++++++++++
1018

11-
For more information about this error, try `rustc --explain E0282`.
12-
error: could not compile `no_type_annotations` due to previous error
19+
For more information about this error, try `rustc --explain E0284`.
20+
error: could not compile `no_type_annotations` (bin "no_type_annotations") due to 1 previous error

src/ch03-00-common-programming-concepts.md

+8-6
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,23 @@ them early will give you a strong core to start from.
2727
これらの基礎は全てのRustプログラムに存在するものであり、それらを早期に学ぶことにより、強力な基礎を築くことになるでしょう。
2828

2929
<!--
30-
> ### Keywords
30+
> #### Keywords
3131
>
32-
> The Rust language has a set of *keywords* that have been reserved for use by
33-
> the language only, much as in other languages. Keep in mind that you cannot
34-
> use these words as names of variables or functions. Most of the keywords have
32+
> The Rust language has a set of *keywords* that are reserved for use by the
33+
> language only, much as in other languages. Keep in mind that you cannot use
34+
> these words as names of variables or functions. Most of the keywords have
3535
> special meanings, and you’ll be using them to do various tasks in your Rust
3636
> programs; a few have no current functionality associated with them but have
3737
> been reserved for functionality that might be added to Rust in the future. You
38-
> can find a list of the keywords in Appendix A.
38+
> can find a list of the keywords in [Appendix A][appendix_a].
3939
-->
4040

41-
> ### キーワード
41+
> #### キーワード
4242
>
4343
> Rust言語にも他の言語同様、キーワードが存在し、これらは言語だけが使用できるようになっています。
4444
> これらの単語は、変数や関数名には使えないことを弁えておいてください。ほとんどのキーワードは、特別な意味を持っており、
4545
> 自らのRustプログラムにおいて、様々な作業をこなすために使用することができます;
4646
> いくつかは、紐付けられた機能がないものの、将来Rustに追加されるかもしれない機能用に予約されています。
4747
> キーワードの一覧は、付録Aで確認できます。
48+
49+
[appendix_a]: appendix-01-keywords.md

0 commit comments

Comments
 (0)