Skip to content

Commit 97d6e0c

Browse files
authored
Merge pull request #146 from rust-lang-ja/update_original_20230602
Update original
2 parents 9f01f7f + fb993e4 commit 97d6e0c

File tree

24 files changed

+140
-69
lines changed

24 files changed

+140
-69
lines changed

src/conversion/string.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ fn main() {
4141
## Stringの解析
4242

4343
<!--
44-
One of the more common types to convert a string into is a number. The idiomatic
44+
One of the more common types to convert a string into a number. The idiomatic
4545
approach to this is to use the [`parse`] function and either to arrange for
4646
type inference or to specify the type to parse using the 'turbofish' syntax.
4747
Both alternatives are shown in the following example.

src/crates/lib.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ Let's create a library, and then see how to link it to another crate.
88
-->
99
ではライブラリを作成し、それを別のクレートにリンクする方法を見ていきましょう。
1010

11+
In `rary.rs`:
12+
1113
```rust,ignore
1214
pub fn public_function() {
1315
println!("called rary's `public_function()`");

src/error/multiple_error_types/reenter_question_mark.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ error:
1111
以前の例では`parse`の呼び出しに対するその場での対応として、エラーをライブラリのエラーからboxされたエラーへと`map`していました。
1212

1313
```rust,ignore
14-
.and_then(|s| s.parse::<i32>()
14+
.and_then(|s| s.parse::<i32>())
1515
.map_err(|e| e.into())
1616
```
1717

src/error/option_unwrap/and_then.md

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ known in some languages as flatmap, comes in.
1515
`and_then()`は引数として与えられた関数にラップされた値を渡しますが、その値が`None`だった場合は`None`を返します。
1616

1717
<!--
18-
In the following example, `cookable_v2()` results in an `Option<Food>`.
18+
In the following example, `cookable_v3()` results in an `Option<Food>`.
1919
Using `map()` instead of `and_then()` would have given an
2020
`Option<Option<Food>>`, which is an invalid type for `eat()`.
2121
-->
22-
以下の例では`cookable_v2()``Option<Food>`を返すため、`and_then()`ではなく`map()`を使用すると最終的に`Option<Option<Food>>`になります。これは`eat()`には不適切な型です。
22+
以下の例では`cookable_v3()``Option<Food>`を返すため、`and_then()`ではなく`map()`を使用すると最終的に`Option<Option<Food>>`になります。これは`eat()`には不適切な型です。
2323

2424
```rust,editable
2525
#![allow(dead_code)]
@@ -52,21 +52,24 @@ fn have_recipe(food: Food) -> Option<Food> {
5252
fn cookable_v1(food: Food) -> Option<Food> {
5353
match have_recipe(food) {
5454
None => None,
55-
Some(food) => match have_ingredients(food) {
56-
None => None,
57-
Some(food) => Some(food),
58-
},
55+
Some(food) => have_ingredients(food),
5956
}
6057
}
6158
6259
// This can conveniently be rewritten more compactly with `and_then()`:
6360
// `and_then()`を用いることで、同じことをよりコンパクトに表現できる。
64-
fn cookable_v2(food: Food) -> Option<Food> {
61+
fn cookable_v3(food: Food) -> Option<Food> {
6562
have_recipe(food).and_then(have_ingredients)
6663
}
6764
65+
// Otherwise we'd need to `flatten()` an `Option<Option<Food>>`
66+
// to get an `Option<Food>`:
67+
fn cookable_v2(food: Food) -> Option<Food> {
68+
have_recipe(food).map(have_ingredients).flatten()
69+
}
70+
6871
fn eat(food: Food, day: Day) {
69-
match cookable_v2(food) {
72+
match cookable_v3(food) {
7073
Some(food) => println!("Yay! On {:?} we get to eat {:?}.", day, food),
7174
None => println!("Oh no. We don't get to eat on {:?}?", day),
7275
}
@@ -87,10 +90,10 @@ fn main() {
8790
### 参照
8891

8992
<!--
90-
[closures][closures], [`Option`][option], and [`Option::and_then()`][and_then]
9193
-->
92-
[closures][closures], [`Option`][option], [`Option::and_then()`][and_then]
94+
[closures][closures], [`Option`][option], [`Option::and_then()`][and_then], and [`Option::flatten()`][flatten]
9395

9496
[closures]: ../../fn/closures.md
9597
[option]: https://doc.rust-lang.org/std/option/enum.Option.html
9698
[and_then]: https://doc.rust-lang.org/std/option/enum.Option.html#method.and_then
99+
[flatten]: https://doc.rust-lang.org/std/option/enum.Option.html#method.flatten

src/error/result/result_map.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,10 @@ use std::num::ParseIntError;
7474
7575
// As with `Option`, we can use combinators such as `map()`.
7676
// This function is otherwise identical to the one above and reads:
77-
// Modify n if the value is valid, otherwise pass on the error.
77+
// Multiply if both values can be parsed from str, otherwise pass on the error.
7878
// `Option`と同様、`map()`などのコンビネータを使うことができます。
7979
// この関数は`map()`を使っている点以外は上記の関数と同じで、
80-
// 値が有効ならnを変更し、無効であればエラーをそのまま見送ります。
80+
// 両方の値がstrからパース可能であればそれらを乗算し、無効であればエラーをそのまま見送ります。
8181
fn multiply(first_number_str: &str, second_number_str: &str) -> Result<i32, ParseIntError> {
8282
first_number_str.parse::<i32>().and_then(|first_number| {
8383
second_number_str.parse::<i32>().map(|second_number| first_number * second_number)

src/flow_control/let_else.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33

44
> 🛈 stable since: rust 1.65
5+
>
6+
> 🛈 you can target specific edition by compiling like this
7+
> `rustc --edition=2021 main.rs`
58
69

710
With `let`-`else`, a refutable pattern can match and bind variables
@@ -22,7 +25,9 @@ fn get_count_item(s: &str) -> (u64, &str) {
2225
(count, item)
2326
}
2427

25-
assert_eq!(get_count_item("3 chairs"), (3, "chairs"));
28+
fn main() {
29+
assert_eq!(get_count_item("3 chairs"), (3, "chairs"));
30+
}
2631
```
2732

2833
The scope of name bindings is the main thing that makes this different from
@@ -57,4 +62,4 @@ patterns with an unfortunate bit of repetition and an outer `let`:
5762
[match]: ./match.md
5863
[if_let]: ./if_let.md
5964
[let_else_rfc]: https://rust-lang.github.io/rfcs/3137-let-else.html
60-
[option]: ../std/option.md
65+
[option]: ../std/option.md

src/flow_control/match/destructuring/destructure_structures.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ fn main() {
3535
// `x`に言及していないため、以下はエラーになる。
3636
//Foo { y } => println!("y = {}", y),
3737
}
38+
39+
let faa = Foo { x: (1, 2), y: 3 };
40+
41+
// You do not need a match block to destructure structs:
42+
let Foo { x : x0, y: y0 } = faa;
43+
println!("Outside: x0 = {x0:?}, y0 = {y0}");
3844
}
3945
```
4046

src/flow_control/match/guard.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ A `match` *guard* can be added to filter the arm.
99
`match`内の条件文をフィルタリングするために、 *ガード(`guard`)* を使用することができます。
1010

1111
```rust,editable
12+
#[allow(dead_code)]
1213
enum Temperature {
1314
Celsius(i32),
1415
Fahrenheit(i32),

src/generics/bounds.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,10 @@ fn main() {
8181
let _triangle = Triangle { length: 3.0, height: 4.0 };
8282
8383
print_debug(&rectangle);
84-
println!("Area: {}", rectangle.area());
84+
println!("Area: {}", area(&rectangle));
8585
8686
//print_debug(&_triangle);
87-
//println!("Area: {}", _triangle.area());
87+
//println!("Area: {}", area(&_triangle));
8888
// ^ TODO: Try uncommenting these.
8989
// | Error: Does not implement either `Debug` or `HasArea`.
9090
// ^ TODO: これらの行をアンコメントしてみましょう。

0 commit comments

Comments
 (0)