Skip to content

ch18 パターンとマッチングの和訳を最新版に更新 #266

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 42 commits into
base: master-ja
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
e685c96
ch02 数当てゲームのプログラミングの和訳を最新版に更新
shinmili May 26, 2024
db3a649
リンク漏れ修正
shinmili Nov 28, 2024
24f5af0
コメントの位置修正
shinmili Dec 26, 2024
cf8947f
ch03 一般的なプログラミングの概念の和訳を最新版に更新
shinmili May 26, 2024
42a63a5
リンク漏れ修正
shinmili Nov 28, 2024
e0d2a48
誤字修正
shinmili Jan 31, 2025
42cf09e
ch04 所有権を理解するの和訳を最新版に更新
shinmili May 26, 2024
138f7fc
コメント閉じ忘れ修正
shinmili Nov 28, 2024
f5f69e9
コードブロックの訳し漏れ修正
shinmili Nov 28, 2024
40d8fd5
ch05 構造体を使用して関係のあるデータを構造化するの和訳を最新版に更新
shinmili May 26, 2024
70c7a13
ch06 Enumとパターンマッチングの和訳を最新版に更新
shinmili May 26, 2024
2f70d34
ch07 肥大化していくプロジェクトをパッケージ、クレート、モジュールを利用して管理するの和訳を最新版に更新
shinmili May 26, 2024
0c0c9d5
消し忘れた段落を削除
shinmili Nov 29, 2024
9eb0aa4
読点の修正
shinmili Nov 29, 2024
1139c13
ch08 一般的なコレクションの和訳を最新版に更新
shinmili May 26, 2024
32a5e00
誤字修正
shinmili Nov 30, 2024
cbd1f9c
消し忘れた段落を削除
shinmili Nov 30, 2024
777e045
コメントの閉じ方の誤りを修正
shinmili Nov 30, 2024
6da5374
修正漏れを修正
shinmili Nov 30, 2024
75aeb75
doc.rust-lang.org 内でのみ機能する相対リンクを修正
shinmili Nov 30, 2024
93e7c99
ch09 エラー処理の和訳を最新版に更新
shinmili May 26, 2024
ee5f863
不要な記号の削除
shinmili Nov 30, 2024
1e6ccf0
消し忘れた段落を削除
shinmili Nov 30, 2024
4e664a9
コメントの位置修正
shinmili Dec 27, 2024
4e3d9ea
ch10 ジェネリック型、トレイト、ライフタイムの和訳を最新版に更新
shinmili May 26, 2024
439eeec
消し忘れた段落を削除
shinmili Nov 30, 2024
fb60cce
ch11 自動テストを書くの和訳を最新版に更新
shinmili May 26, 2024
91b9e1a
見出しレベル誤りを修正
shinmili Dec 1, 2024
059af4e
消し忘れた段落を削除
shinmili Dec 1, 2024
5464a6e
余計な空行を削除
shinmili Dec 27, 2024
06f787f
訳し漏れの翻訳を追加
shinmili Jan 31, 2025
fff91f0
誤字修正
shinmili Jan 31, 2025
57c5588
ch12 入出力プロジェクト: コマンドラインプログラムを構築するの和訳を最新版に更新
shinmili May 26, 2024
e042c99
ch13 関数型言語の機能: イテレータとクロージャの和訳を最新版に更新
shinmili May 26, 2024
4543380
見出しレベル誤りを修正
shinmili Dec 1, 2024
57b18f1
訳し忘れを修正
shinmili Dec 1, 2024
db47fd2
ch14 CargoとCrates.ioについてより詳しくの和訳を最新版に更新
shinmili May 26, 2024
e3bf9f9
ch15 スマートポインタの和訳を最新版に更新
shinmili May 26, 2024
e49e340
消し忘れた段落を削除
shinmili Dec 7, 2024
64432c2
ch16 恐れるな!並行性の和訳を最新版に更新
shinmili May 26, 2024
bd648eb
ch17 Rustのオブジェクト指向プログラミング機能の和訳を最新版に更新
shinmili May 26, 2024
7f4328c
ch18 パターンとマッチングの和訳を最新版に更新
shinmili May 26, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
ch16 恐れるな!並行性の和訳を最新版に更新
  • Loading branch information
shinmili committed Feb 4, 2025
commit 64432c24f67c23525e8339b2db6851c70bc87663
3 changes: 1 addition & 2 deletions listings/ch16-fearless-concurrency/listing-16-01/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[package]
name = "threads"
version = "0.1.0"
authors = ["Your Name <you@example.com>"]
edition = "2018"
edition = "2021"

[dependencies]
2 changes: 2 additions & 0 deletions listings/ch16-fearless-concurrency/listing-16-01/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ use std::time::Duration;
fn main() {
thread::spawn(|| {
for i in 1..10 {
// "やあ!立ち上げたスレッドから数字{}だよ!"
println!("hi number {} from the spawned thread!", i);
thread::sleep(Duration::from_millis(1));
}
});

for i in 1..5 {
// "やあ!メインスレッドから数字{}だよ!"
println!("hi number {} from the main thread!", i);
thread::sleep(Duration::from_millis(1));
}
Expand Down
3 changes: 1 addition & 2 deletions listings/ch16-fearless-concurrency/listing-16-02/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[package]
name = "threads"
version = "0.1.0"
authors = ["Your Name <you@example.com>"]
edition = "2018"
edition = "2021"

[dependencies]
3 changes: 1 addition & 2 deletions listings/ch16-fearless-concurrency/listing-16-03/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[package]
name = "threads"
version = "0.1.0"
authors = ["Your Name <you@example.com>"]
edition = "2018"
edition = "2021"

[dependencies]
13 changes: 7 additions & 6 deletions listings/ch16-fearless-concurrency/listing-16-03/output.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
$ cargo run
Compiling threads v0.1.0 (file:///projects/threads)
error[E0373]: closure may outlive the current function, but it borrows `v`, which is owned by the current function
(エラー: クロージャは現在の関数よりも長生きするかもしれませんが、現在の関数が所有している`v`を借用しています)
--> src/main.rs:6:32
|
6 | let handle = thread::spawn(|| {
| ^^ may outlive borrowed value `v`
| (借用されている値`v`より長生きするかもしれません)
7 | println!("Here's a vector: {:?}", v);
| - `v` is borrowed here
| (`v`はここで借用されています)
|
note: function requires argument type to outlive `'static`
(注釈: 関数は引数型が`'static`より長生きすることを要求しています)
--> src/main.rs:6:18
|
6 | let handle = thread::spawn(|| {
Expand All @@ -17,13 +21,10 @@ note: function requires argument type to outlive `'static`
8 | | });
| |______^
help: to force the closure to take ownership of `v` (and any other referenced variables), use the `move` keyword
(ヘルプ: `v`(や他の参照されている変数)の所有権をクロージャに奪わせるには、`move`キーワードを使用してください)
|
6 | let handle = thread::spawn(move || {
| ^^^^^^^

error: aborting due to previous error
| ++++

For more information about this error, try `rustc --explain E0373`.
error: could not compile `threads`.

To learn more, run the command again with --verbose.
error: could not compile `threads` (bin "threads") due to 1 previous error
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ fn main() {
let v = vec![1, 2, 3];

let handle = thread::spawn(|| {
// "こちらがベクタ: {:?}"
println!("Here's a vector: {:?}", v);
});

Expand Down
3 changes: 1 addition & 2 deletions listings/ch16-fearless-concurrency/listing-16-04/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[package]
name = "threads"
version = "0.1.0"
authors = ["Your Name <you@example.com>"]
edition = "2018"
edition = "2021"

[dependencies]
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ fn main() {
println!("Here's a vector: {:?}", v);
});

drop(v); // oh no!
drop(v); // あちゃー!

handle.join().unwrap();
}
3 changes: 1 addition & 2 deletions listings/ch16-fearless-concurrency/listing-16-05/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[package]
name = "threads"
version = "0.1.0"
authors = ["Your Name <you@example.com>"]
edition = "2018"
edition = "2021"

[dependencies]
3 changes: 1 addition & 2 deletions listings/ch16-fearless-concurrency/listing-16-06/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[package]
name = "message-passing"
version = "0.1.0"
authors = ["Your Name <you@example.com>"]
edition = "2018"
edition = "2021"

[dependencies]
3 changes: 1 addition & 2 deletions listings/ch16-fearless-concurrency/listing-16-07/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[package]
name = "message-passing"
version = "0.1.0"
authors = ["Your Name <you@example.com>"]
edition = "2018"
edition = "2021"

[dependencies]
3 changes: 1 addition & 2 deletions listings/ch16-fearless-concurrency/listing-16-08/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[package]
name = "message-passing"
version = "0.1.0"
authors = ["Your Name <you@example.com>"]
edition = "2018"
edition = "2021"

[dependencies]
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ fn main() {
});

let received = rx.recv().unwrap();
// "取得しました: {}"
println!("Got: {}", received);
}
3 changes: 1 addition & 2 deletions listings/ch16-fearless-concurrency/listing-16-09/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[package]
name = "message-passing"
version = "0.1.0"
authors = ["Your Name <you@example.com>"]
edition = "2018"
edition = "2021"

[dependencies]
19 changes: 13 additions & 6 deletions listings/ch16-fearless-concurrency/listing-16-09/output.txt
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
$ cargo run
Compiling message-passing v0.1.0 (file:///projects/message-passing)
error[E0382]: borrow of moved value: `val`
(エラー: ムーブされた値の借用: `val`)
--> src/main.rs:10:31
|
8 | let val = String::from("hi");
| --- move occurs because `val` has type `std::string::String`, which does not implement the `Copy` trait
| --- move occurs because `val` has type `String`, which does not implement the `Copy` trait
| (`val`は`Copy`トレイトを実装しない`String`型を持つので、ムーブが発生します)
9 | tx.send(val).unwrap();
| --- value moved here
| (値はここでムーブされます)
10 | println!("val is {}", val);
| ^^^ value borrowed here after move

error: aborting due to previous error
| (ここでムーブ後に借用されます)
|
= note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider cloning the value if the performance cost is acceptable
(ヘルプ: パフォーマンスコストが許容できる場合は、クローンすることを検討してください)
|
9 | tx.send(val.clone()).unwrap();
| ++++++++

For more information about this error, try `rustc --explain E0382`.
error: could not compile `message-passing`.

To learn more, run the command again with --verbose.
error: could not compile `message-passing` (bin "message-passing") due to 1 previous error
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ fn main() {
thread::spawn(move || {
let val = String::from("hi");
tx.send(val).unwrap();
// "valは{}です"
println!("val is {}", val);
});

Expand Down
3 changes: 1 addition & 2 deletions listings/ch16-fearless-concurrency/listing-16-10/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[package]
name = "message-passing"
version = "0.1.0"
authors = ["Your Name <you@example.com>"]
edition = "2018"
edition = "2021"

[dependencies]
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ fn main() {
let (tx, rx) = mpsc::channel();

thread::spawn(move || {
// スレッドからやあ (hi from the thread)
let vals = vec![
String::from("hi"),
String::from("from"),
Expand Down
3 changes: 1 addition & 2 deletions listings/ch16-fearless-concurrency/listing-16-11/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[package]
name = "message-passing"
version = "0.1.0"
authors = ["Your Name <you@example.com>"]
edition = "2018"
edition = "2021"

[dependencies]
3 changes: 2 additions & 1 deletion listings/ch16-fearless-concurrency/listing-16-11/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ fn main() {

let (tx, rx) = mpsc::channel();

let tx1 = mpsc::Sender::clone(&tx);
let tx1 = tx.clone();
thread::spawn(move || {
let vals = vec![
String::from("hi"),
Expand All @@ -24,6 +24,7 @@ fn main() {
});

thread::spawn(move || {
// 君のためにもっとメッセージを (more messages for you)
let vals = vec![
String::from("more"),
String::from("messages"),
Expand Down
3 changes: 1 addition & 2 deletions listings/ch16-fearless-concurrency/listing-16-12/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[package]
name = "shared-state"
version = "0.1.0"
authors = ["Your Name <you@example.com>"]
edition = "2018"
edition = "2021"

[dependencies]
3 changes: 1 addition & 2 deletions listings/ch16-fearless-concurrency/listing-16-13/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[package]
name = "shared-state"
version = "0.1.0"
authors = ["Your Name <you@example.com>"]
edition = "2018"
edition = "2021"

[dependencies]
23 changes: 12 additions & 11 deletions listings/ch16-fearless-concurrency/listing-16-13/output.txt
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
$ cargo run
Compiling shared-state v0.1.0 (file:///projects/shared-state)
error[E0382]: use of moved value: `counter`
--> src/main.rs:9:36
error[E0382]: borrow of moved value: `counter`
(エラー: ムーブされた値の借用: `counter`)
--> src/main.rs:21:29
|
5 | let counter = Mutex::new(0);
| ------- move occurs because `counter` has type `std::sync::Mutex<i32>`, which does not implement the `Copy` trait
| ------- move occurs because `counter` has type `Mutex<i32>`, which does not implement the `Copy` trait
| (`counter`は`Copy`トレイトを実装しない`Mutex<i32>`型を持つので、ムーブが発生します)
...
9 | let handle = thread::spawn(move || {
| ^^^^^^^ value moved into closure here, in previous iteration of loop
10 | let mut num = counter.lock().unwrap();
| ------- use occurs due to use in closure

error: aborting due to previous error
| ------- value moved into closure here, in previous iteration of loop
| (値は、ループの前回の反復時に、ここでクロージャ内にムーブされます)
...
21 | println!("Result: {}", *counter.lock().unwrap());
| ^^^^^^^ value borrowed here after move
| (値はここでムーブ後に借用されています)

For more information about this error, try `rustc --explain E0382`.
error: could not compile `shared-state`.

To learn more, run the command again with --verbose.
error: could not compile `shared-state` (bin "shared-state") due to 1 previous error
3 changes: 1 addition & 2 deletions listings/ch16-fearless-concurrency/listing-16-14/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[package]
name = "shared-state"
version = "0.1.0"
authors = ["Your Name <you@example.com>"]
edition = "2018"
edition = "2021"

[dependencies]
44 changes: 31 additions & 13 deletions listings/ch16-fearless-concurrency/listing-16-14/output.txt
Original file line number Diff line number Diff line change
@@ -1,17 +1,35 @@
$ cargo run
Compiling shared-state v0.1.0 (file:///projects/shared-state)
error[E0277]: `std::rc::Rc<std::sync::Mutex<i32>>` cannot be sent between threads safely
--> src/main.rs:11:22
|
11 | let handle = thread::spawn(move || {
| ^^^^^^^^^^^^^ `std::rc::Rc<std::sync::Mutex<i32>>` cannot be sent between threads safely
|
= help: within `[closure@src/main.rs:11:36: 15:10 counter:std::rc::Rc<std::sync::Mutex<i32>>]`, the trait `std::marker::Send` is not implemented for `std::rc::Rc<std::sync::Mutex<i32>>`
= note: required because it appears within the type `[closure@src/main.rs:11:36: 15:10 counter:std::rc::Rc<std::sync::Mutex<i32>>]`

error: aborting due to previous error
error[E0277]: `Rc<Mutex<i32>>` cannot be sent between threads safely
(エラー: `Rc<Mutex<i32>>`はスレッド間で安全に送信できません)
--> src/main.rs:11:36
|
11 | let handle = thread::spawn(move || {
| ------------- ^------
| | |
| ______________________|_____________within this `{closure@src/main.rs:11:36: 11:43}`
| | | (この`{[closure@src/main.rs:11:36: 11:43}`の中で)
| | |
| | required by a bound introduced by this call
| | (この呼び出しによって導入される境界によって必要とされます)
12 | | let mut num = counter.lock().unwrap();
13 | |
14 | | *num += 1;
15 | | });
| |_________^ `Rc<Mutex<i32>>` cannot be sent between threads safely
| (`Rc<Mutex<i32>>`はスレッド間で安全に送信できません)
|
= help: within `{closure@src/main.rs:11:36: 11:43}`, the trait `Send` is not implemented for `Rc<Mutex<i32>>`
=(ヘルプ: `{closure@src/main.rs:11:36: 11:43}`の中で、トレイト`Send`は`Rc<Mutex<i32>>`に対して実装されていません
note: required because it's used within this closure
(注釈: このクロージャの中で使用されているので、要求されます)
--> src/main.rs:11:36
|
11 | let handle = thread::spawn(move || {
| ^^^^^^^
note: required by a bound in `spawn`
(注釈: `spawn`の境界によって要求されます)
--> /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/thread/mod.rs:678:1

For more information about this error, try `rustc --explain E0277`.
error: could not compile `shared-state`.

To learn more, run the command again with --verbose.
error: could not compile `shared-state` (bin "shared-state") due to 1 previous error
3 changes: 1 addition & 2 deletions listings/ch16-fearless-concurrency/listing-16-15/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[package]
name = "shared-state"
version = "0.1.0"
authors = ["Your Name <you@example.com>"]
edition = "2018"
edition = "2021"

[dependencies]
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[package]
name = "threads"
version = "0.1.0"
authors = ["Your Name <you@example.com>"]
edition = "2018"
edition = "2021"

[dependencies]
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[package]
name = "shared-state"
version = "0.1.0"
authors = ["Your Name <you@example.com>"]
edition = "2018"
edition = "2021"

[dependencies]
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[package]
name = "threads"
version = "0.1.0"
authors = ["Your Name <you@example.com>"]
edition = "2018"
edition = "2021"

[dependencies]
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy