Skip to content

Commit 57c5588

Browse files
committed
ch12 入出力プロジェクト: コマンドラインプログラムを構築するの和訳を最新版に更新
rust-lang/book@19c40bf
1 parent fff91f0 commit 57c5588

File tree

125 files changed

+1129
-1594
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

125 files changed

+1129
-1594
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
[package]
22
name = "minigrep"
33
version = "0.1.0"
4-
authors = ["Your Name <[email protected]>"]
5-
edition = "2018"
4+
edition = "2021"
65

76
[dependencies]

listings/ch12-an-io-project/listing-12-01/output.txt

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@ $ cargo run
22
Compiling minigrep v0.1.0 (file:///projects/minigrep)
33
Finished dev [unoptimized + debuginfo] target(s) in 0.61s
44
Running `target/debug/minigrep`
5-
["target/debug/minigrep"]
5+
[src/main.rs:5:5] args = [
6+
"target/debug/minigrep",
7+
]

listings/ch12-an-io-project/listing-12-01/src/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ use std::env;
22

33
fn main() {
44
let args: Vec<String> = env::args().collect();
5-
println!("{:?}", args);
5+
dbg!(args);
66
}
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
[package]
22
name = "minigrep"
33
version = "0.1.0"
4-
authors = ["Your Name <[email protected]>"]
5-
edition = "2018"
4+
edition = "2021"
65

76
[dependencies]

listings/ch12-an-io-project/listing-12-02/output.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
$ cargo run test sample.txt
1+
$ cargo run -- test sample.txt
22
Compiling minigrep v0.1.0 (file:///projects/minigrep)
33
Finished dev [unoptimized + debuginfo] target(s) in 0.0s
44
Running `target/debug/minigrep test sample.txt`

listings/ch12-an-io-project/listing-12-02/src/main.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ fn main() {
44
let args: Vec<String> = env::args().collect();
55

66
let query = &args[1];
7-
let filename = &args[2];
7+
let file_path = &args[2];
88

9+
// "{}を検索します"
910
println!("Searching for {}", query);
10-
println!("In file {}", filename);
11+
// "ファイル{}の中で"
12+
println!("In file {}", file_path);
1113
}
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
[package]
22
name = "minigrep"
33
version = "0.1.0"
4-
authors = ["Your Name <[email protected]>"]
5-
edition = "2018"
4+
edition = "2021"
65

76
[dependencies]

listings/ch12-an-io-project/listing-12-03/poem.txt

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
Im nobody! Who are you?
1+
I'm nobody! Who are you?
22
Are you nobody, too?
3-
Then theres a pair of us - dont tell!
4-
Theyd banish us, you know.
3+
Then there's a pair of us - don't tell!
4+
They'd banish us, you know.
55

66
How dreary to be somebody!
77
How public, like a frog

listings/ch12-an-io-project/listing-12-03/src/main.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ fn main() {
44
let args: Vec<String> = env::args().collect();
55

66
let query = &args[1];
7-
let filename = &args[2];
7+
let file_path = &args[2];
88

99
println!("Searching for {}", query);
10-
println!("In file {}", filename);
10+
println!("In file {}", file_path);
1111
}
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
[package]
22
name = "minigrep"
33
version = "0.1.0"
4-
authors = ["Your Name <[email protected]>"]
5-
edition = "2018"
4+
edition = "2021"
65

76
[dependencies]

listings/ch12-an-io-project/listing-12-04/output.txt

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
$ cargo run the poem.txt
1+
$ cargo run -- the poem.txt
22
Compiling minigrep v0.1.0 (file:///projects/minigrep)
33
Finished dev [unoptimized + debuginfo] target(s) in 0.0s
44
Running `target/debug/minigrep the poem.txt`
55
Searching for the
66
In file poem.txt
77
With text:
8-
Im nobody! Who are you?
8+
I'm nobody! Who are you?
99
Are you nobody, too?
10-
Then theres a pair of us - dont tell!
11-
Theyd banish us, you know.
10+
Then there's a pair of us - don't tell!
11+
They'd banish us, you know.
1212

1313
How dreary to be somebody!
1414
How public, like a frog

listings/ch12-an-io-project/listing-12-04/poem.txt

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
Im nobody! Who are you?
1+
I'm nobody! Who are you?
22
Are you nobody, too?
3-
Then theres a pair of us - dont tell!
4-
Theyd banish us, you know.
3+
Then there's a pair of us - don't tell!
4+
They'd banish us, you know.
55

66
How dreary to be somebody!
77
How public, like a frog

listings/ch12-an-io-project/listing-12-04/src/main.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,17 @@ fn main() {
88
let args: Vec<String> = env::args().collect();
99

1010
let query = &args[1];
11-
let filename = &args[2];
11+
let file_path = &args[2];
1212

1313
println!("Searching for {}", query);
1414
// ANCHOR: here
15-
println!("In file {}", filename);
15+
println!("In file {}", file_path);
1616

17-
let contents = fs::read_to_string(filename)
18-
.expect("Something went wrong reading the file");
17+
let contents = fs::read_to_string(file_path)
18+
// "ファイルを読み込むことができるはずでした"
19+
.expect("Should have been able to read the file");
1920

20-
println!("With text:\n{}", contents);
21+
// "テキスト:\n{contents}"
22+
println!("With text:\n{contents}");
2123
}
2224
// ANCHOR_END: here
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
[package]
22
name = "minigrep"
33
version = "0.1.0"
4-
authors = ["Your Name <[email protected]>"]
5-
edition = "2018"
4+
edition = "2021"
65

76
[dependencies]

listings/ch12-an-io-project/listing-12-05/poem.txt

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
Im nobody! Who are you?
1+
I'm nobody! Who are you?
22
Are you nobody, too?
3-
Then theres a pair of us - dont tell!
4-
Theyd banish us, you know.
3+
Then there's a pair of us - don't tell!
4+
They'd banish us, you know.
55

66
How dreary to be somebody!
77
How public, like a frog

listings/ch12-an-io-project/listing-12-05/src/main.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,25 @@ use std::fs;
55
fn main() {
66
let args: Vec<String> = env::args().collect();
77

8-
let (query, filename) = parse_config(&args);
8+
let (query, file_path) = parse_config(&args);
99

1010
// --snip--
1111
// ANCHOR_END: here
1212

1313
println!("Searching for {}", query);
14-
println!("In file {}", filename);
14+
println!("In file {}", file_path);
1515

16-
let contents = fs::read_to_string(filename)
17-
.expect("Something went wrong reading the file");
16+
let contents = fs::read_to_string(file_path)
17+
.expect("Should have been able to read the file");
1818

19-
println!("With text:\n{}", contents);
19+
println!("With text:\n{contents}");
2020
// ANCHOR: here
2121
}
2222

2323
fn parse_config(args: &[String]) -> (&str, &str) {
2424
let query = &args[1];
25-
let filename = &args[2];
25+
let file_path = &args[2];
2626

27-
(query, filename)
27+
(query, file_path)
2828
}
2929
// ANCHOR_END: here
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
[package]
22
name = "minigrep"
33
version = "0.1.0"
4-
authors = ["Your Name <[email protected]>"]
5-
edition = "2018"
4+
edition = "2021"
65

76
[dependencies]

listings/ch12-an-io-project/listing-12-06/poem.txt

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
Im nobody! Who are you?
1+
I'm nobody! Who are you?
22
Are you nobody, too?
3-
Then theres a pair of us - dont tell!
4-
Theyd banish us, you know.
3+
Then there's a pair of us - don't tell!
4+
They'd banish us, you know.
55

66
How dreary to be somebody!
77
How public, like a frog

listings/ch12-an-io-project/listing-12-06/src/main.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,27 @@ fn main() {
88
let config = parse_config(&args);
99

1010
println!("Searching for {}", config.query);
11-
println!("In file {}", config.filename);
11+
println!("In file {}", config.file_path);
1212

13-
let contents = fs::read_to_string(config.filename)
14-
.expect("Something went wrong reading the file");
13+
let contents = fs::read_to_string(config.file_path)
14+
.expect("Should have been able to read the file");
1515

1616
// --snip--
1717
// ANCHOR_END: here
1818

19-
println!("With text:\n{}", contents);
19+
println!("With text:\n{contents}");
2020
// ANCHOR: here
2121
}
2222

2323
struct Config {
2424
query: String,
25-
filename: String,
25+
file_path: String,
2626
}
2727

2828
fn parse_config(args: &[String]) -> Config {
2929
let query = args[1].clone();
30-
let filename = args[2].clone();
30+
let file_path = args[2].clone();
3131

32-
Config { query, filename }
32+
Config { query, file_path }
3333
}
3434
// ANCHOR_END: here
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
[package]
22
name = "minigrep"
33
version = "0.1.0"
4-
authors = ["Your Name <[email protected]>"]
5-
edition = "2018"
4+
edition = "2021"
65

76
[dependencies]

listings/ch12-an-io-project/listing-12-07/output.txt

+5-2
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,8 @@ $ cargo run
22
Compiling minigrep v0.1.0 (file:///projects/minigrep)
33
Finished dev [unoptimized + debuginfo] target(s) in 0.0s
44
Running `target/debug/minigrep`
5-
thread 'main' panicked at 'index out of bounds: the len is 1 but the index is 1', src/main.rs:27:21
6-
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
5+
thread 'main' panicked at src/main.rs:27:21:
6+
index out of bounds: the len is 1 but the index is 1
7+
(スレッド'main'はsrc/main.rs:27:21でパニックしました:
8+
境界外アクセス: 長さは1なのに添え字も1です)
9+
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

listings/ch12-an-io-project/listing-12-07/poem.txt

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
Im nobody! Who are you?
1+
I'm nobody! Who are you?
22
Are you nobody, too?
3-
Then theres a pair of us - dont tell!
4-
Theyd banish us, you know.
3+
Then there's a pair of us - don't tell!
4+
They'd banish us, you know.
55

66
How dreary to be somebody!
77
How public, like a frog

listings/ch12-an-io-project/listing-12-07/src/main.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ fn main() {
99
// ANCHOR_END: here
1010

1111
println!("Searching for {}", config.query);
12-
println!("In file {}", config.filename);
12+
println!("In file {}", config.file_path);
1313

14-
let contents = fs::read_to_string(config.filename)
15-
.expect("Something went wrong reading the file");
14+
let contents = fs::read_to_string(config.file_path)
15+
.expect("Should have been able to read the file");
1616

17-
println!("With text:\n{}", contents);
17+
println!("With text:\n{contents}");
1818
// ANCHOR: here
1919

2020
// --snip--
@@ -25,16 +25,16 @@ fn main() {
2525
// ANCHOR_END: here
2626
struct Config {
2727
query: String,
28-
filename: String,
28+
file_path: String,
2929
}
3030

3131
// ANCHOR: here
3232
impl Config {
3333
fn new(args: &[String]) -> Config {
3434
let query = args[1].clone();
35-
let filename = args[2].clone();
35+
let file_path = args[2].clone();
3636

37-
Config { query, filename }
37+
Config { query, file_path }
3838
}
3939
}
4040
// ANCHOR_END: here
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
[package]
22
name = "minigrep"
33
version = "0.1.0"
4-
authors = ["Your Name <[email protected]>"]
5-
edition = "2018"
4+
edition = "2021"
65

76
[dependencies]

listings/ch12-an-io-project/listing-12-08/output.txt

+5-2
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,8 @@ $ cargo run
22
Compiling minigrep v0.1.0 (file:///projects/minigrep)
33
Finished dev [unoptimized + debuginfo] target(s) in 0.0s
44
Running `target/debug/minigrep`
5-
thread 'main' panicked at 'not enough arguments', src/main.rs:26:13
6-
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
5+
thread 'main' panicked at src/main.rs:26:13:
6+
not enough arguments
7+
(スレッド'main'はsrc/main.rs:26:13でパニックしました:
8+
引数が足りません)
9+
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

listings/ch12-an-io-project/listing-12-08/poem.txt

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
Im nobody! Who are you?
1+
I'm nobody! Who are you?
22
Are you nobody, too?
3-
Then theres a pair of us - dont tell!
4-
Theyd banish us, you know.
3+
Then there's a pair of us - don't tell!
4+
They'd banish us, you know.
55

66
How dreary to be somebody!
77
How public, like a frog

listings/ch12-an-io-project/listing-12-08/src/main.rs

+8-7
Original file line numberDiff line numberDiff line change
@@ -7,32 +7,33 @@ fn main() {
77
let config = Config::new(&args);
88

99
println!("Searching for {}", config.query);
10-
println!("In file {}", config.filename);
10+
println!("In file {}", config.file_path);
1111

12-
let contents = fs::read_to_string(config.filename)
13-
.expect("Something went wrong reading the file");
12+
let contents = fs::read_to_string(config.file_path)
13+
.expect("Should have been able to read the file");
1414

15-
println!("With text:\n{}", contents);
15+
println!("With text:\n{contents}");
1616
}
1717

1818
struct Config {
1919
query: String,
20-
filename: String,
20+
file_path: String,
2121
}
2222

2323
impl Config {
2424
// ANCHOR: here
2525
// --snip--
2626
fn new(args: &[String]) -> Config {
2727
if args.len() < 3 {
28+
// "引数が足りません"
2829
panic!("not enough arguments");
2930
}
3031
// --snip--
3132
// ANCHOR_END: here
3233

3334
let query = args[1].clone();
34-
let filename = args[2].clone();
35+
let file_path = args[2].clone();
3536

36-
Config { query, filename }
37+
Config { query, file_path }
3738
}
3839
}

0 commit comments

Comments
 (0)