Skip to content

Commit 20bed51

Browse files
committed
ch07 肥大化していくプロジェクトをパッケージ、クレート、モジュールを利用して管理するの和訳を最新版に更新
rust-lang/book@19c40bf
1 parent 0de9bcf commit 20bed51

File tree

48 files changed

+950
-577
lines changed

Some content is hidden

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

48 files changed

+950
-577
lines changed
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
[package]
22
name = "restaurant"
33
version = "0.1.0"
4-
authors = ["Your Name <you@example.com>"]
5-
edition = "2018"
4+
edition = "2021"
65

76
[dependencies]

listings/ch07-managing-growing-projects/listing-07-01/src/lib.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// ANCHOR: here
21
mod front_of_house {
32
mod hosting {
43
fn add_to_waitlist() {}
@@ -14,6 +13,3 @@ mod front_of_house {
1413
fn take_payment() {}
1514
}
1615
}
17-
// ANCHOR_END: here
18-
19-
fn main() {}
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
[package]
22
name = "restaurant"
33
version = "0.1.0"
4-
authors = ["Your Name <you@example.com>"]
5-
edition = "2018"
4+
edition = "2021"
65

76
[dependencies]

listings/ch07-managing-growing-projects/listing-07-03/output.txt

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,29 @@ error[E0603]: module `hosting` is private
44
--> src/lib.rs:9:28
55
|
66
9 | crate::front_of_house::hosting::add_to_waitlist();
7-
| ^^^^^^^
7+
| ^^^^^^^ --------------- function `add_to_waitlist` is not publicly re-exported
8+
| |
9+
| private module
10+
|
11+
note: the module `hosting` is defined here
12+
--> src/lib.rs:2:5
13+
|
14+
2 | mod hosting {
15+
| ^^^^^^^^^^^
816

917
error[E0603]: module `hosting` is private
1018
--> src/lib.rs:12:21
1119
|
1220
12 | front_of_house::hosting::add_to_waitlist();
13-
| ^^^^^^^
14-
15-
error: aborting due to 2 previous errors
21+
| ^^^^^^^ --------------- function `add_to_waitlist` is not publicly re-exported
22+
| |
23+
| private module
24+
|
25+
note: the module `hosting` is defined here
26+
--> src/lib.rs:2:5
27+
|
28+
2 | mod hosting {
29+
| ^^^^^^^^^^^
1630

1731
For more information about this error, try `rustc --explain E0603`.
18-
error: could not compile `restaurant`.
19-
20-
To learn more, run the command again with --verbose.
32+
error: could not compile `restaurant` (lib) due to 2 previous errors
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
[package]
22
name = "restaurant"
33
version = "0.1.0"
4-
authors = ["Your Name <you@example.com>"]
5-
edition = "2018"
4+
edition = "2021"
65

76
[dependencies]

listings/ch07-managing-growing-projects/listing-07-05/output.txt

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,25 @@ error[E0603]: function `add_to_waitlist` is private
44
--> src/lib.rs:9:37
55
|
66
9 | crate::front_of_house::hosting::add_to_waitlist();
7-
| ^^^^^^^^^^^^^^^
7+
| ^^^^^^^^^^^^^^^ private function
8+
|
9+
note: the function `add_to_waitlist` is defined here
10+
--> src/lib.rs:3:9
11+
|
12+
3 | fn add_to_waitlist() {}
13+
| ^^^^^^^^^^^^^^^^^^^^
814

915
error[E0603]: function `add_to_waitlist` is private
1016
--> src/lib.rs:12:30
1117
|
1218
12 | front_of_house::hosting::add_to_waitlist();
13-
| ^^^^^^^^^^^^^^^
14-
15-
error: aborting due to 2 previous errors
19+
| ^^^^^^^^^^^^^^^ private function
20+
|
21+
note: the function `add_to_waitlist` is defined here
22+
--> src/lib.rs:3:9
23+
|
24+
3 | fn add_to_waitlist() {}
25+
| ^^^^^^^^^^^^^^^^^^^^
1626

1727
For more information about this error, try `rustc --explain E0603`.
18-
error: could not compile `restaurant`.
19-
20-
To learn more, run the command again with --verbose.
28+
error: could not compile `restaurant` (lib) due to 2 previous errors
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
[package]
22
name = "restaurant"
33
version = "0.1.0"
4-
authors = ["Your Name <you@example.com>"]
5-
edition = "2018"
4+
edition = "2021"
65

76
[dependencies]

listings/ch07-managing-growing-projects/listing-07-07/src/lib.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// ANCHOR: here
21
mod front_of_house {
32
pub mod hosting {
43
pub fn add_to_waitlist() {}
@@ -14,6 +13,3 @@ pub fn eat_at_restaurant() {
1413
// 相対パス
1514
front_of_house::hosting::add_to_waitlist();
1615
}
17-
// ANCHOR_END: here
18-
19-
fn main() {}
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
[package]
22
name = "restaurant"
33
version = "0.1.0"
4-
authors = ["Your Name <you@example.com>"]
5-
edition = "2018"
4+
edition = "2021"
65

76
[dependencies]
Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
1-
// ANCHOR: here
2-
fn serve_order() {}
1+
fn deliver_order() {}
32

43
mod back_of_house {
54
fn fix_incorrect_order() {
65
cook_order();
7-
super::serve_order();
6+
super::deliver_order();
87
}
98

109
fn cook_order() {}
1110
}
12-
// ANCHOR_END: here
13-
14-
fn main() {}
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
[package]
22
name = "restaurant"
33
version = "0.1.0"
4-
authors = ["Your Name <you@example.com>"]
5-
edition = "2018"
4+
edition = "2021"
65

76
[dependencies]
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
[package]
22
name = "restaurant"
33
version = "0.1.0"
4-
authors = ["Your Name <you@example.com>"]
5-
edition = "2018"
4+
edition = "2021"
65

76
[dependencies]
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
[package]
22
name = "restaurant"
33
version = "0.1.0"
4-
authors = ["Your Name <you@example.com>"]
5-
edition = "2018"
4+
edition = "2021"
65

76
[dependencies]
Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// ANCHOR: here
21
mod front_of_house {
32
pub mod hosting {
43
pub fn add_to_waitlist() {}
@@ -9,9 +8,4 @@ use crate::front_of_house::hosting;
98

109
pub fn eat_at_restaurant() {
1110
hosting::add_to_waitlist();
12-
hosting::add_to_waitlist();
13-
hosting::add_to_waitlist();
1411
}
15-
// ANCHOR_END: here
16-
17-
fn main() {}
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
[package]
22
name = "restaurant"
33
version = "0.1.0"
4-
authors = ["Your Name <you@example.com>"]
5-
edition = "2018"
4+
edition = "2021"
65

76
[dependencies]
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
$ cargo build
2+
Compiling restaurant v0.1.0 (file:///projects/restaurant)
3+
error[E0433]: failed to resolve: use of undeclared crate or module `hosting`
4+
(エラー: 名前解決に失敗しました: 宣言されていないクレートまたはモジュール`hosting`の使用)
5+
--> src/lib.rs:11:9
6+
|
7+
11 | hosting::add_to_waitlist();
8+
| ^^^^^^^ use of undeclared crate or module `hosting`
9+
| (宣言されていないクレートまたはモジュール`hosting`の使用)
10+
|
11+
help: consider importing this module through its public re-export
12+
(ヘルプ: 公開再エクスポートからこのモジュールをインポートすることを検討してください)
13+
|
14+
10 + use crate::hosting;
15+
|
16+
17+
warning: unused import: `crate::front_of_house::hosting`
18+
(警告: 未使用のインポート: `crate::front_of_house::hosting`)
19+
--> src/lib.rs:7:5
20+
|
21+
7 | use crate::front_of_house::hosting;
22+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
23+
|
24+
= note: `#[warn(unused_imports)]` on by default
25+
26+
For more information about this error, try `rustc --explain E0433`.
27+
warning: `restaurant` (lib) generated 1 warning
28+
error: could not compile `restaurant` (lib) due to 1 previous error; 1 warning emitted
Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
1-
// ANCHOR: here
21
mod front_of_house {
32
pub mod hosting {
43
pub fn add_to_waitlist() {}
54
}
65
}
76

8-
use self::front_of_house::hosting;
7+
use crate::front_of_house::hosting;
98

10-
pub fn eat_at_restaurant() {
11-
hosting::add_to_waitlist();
12-
hosting::add_to_waitlist();
13-
hosting::add_to_waitlist();
9+
mod customer {
10+
pub fn eat_at_restaurant() {
11+
hosting::add_to_waitlist();
12+
}
1413
}
15-
// ANCHOR_END: here
16-
17-
fn main() {}
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
[package]
22
name = "restaurant"
33
version = "0.1.0"
4-
authors = ["Your Name <you@example.com>"]
5-
edition = "2018"
4+
edition = "2021"
65

76
[dependencies]
Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// ANCHOR: here
21
mod front_of_house {
32
pub mod hosting {
43
pub fn add_to_waitlist() {}
@@ -9,9 +8,4 @@ use crate::front_of_house::hosting::add_to_waitlist;
98

109
pub fn eat_at_restaurant() {
1110
add_to_waitlist();
12-
add_to_waitlist();
13-
add_to_waitlist();
1411
}
15-
// ANCHOR_END: here
16-
17-
fn main() {}
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
[package]
22
name = "restaurant"
33
version = "0.1.0"
4-
authors = ["Your Name <you@example.com>"]
5-
edition = "2018"
4+
edition = "2021"
65

76
[dependencies]
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
[package]
22
name = "restaurant"
33
version = "0.1.0"
4-
authors = ["Your Name <you@example.com>"]
5-
edition = "2018"
4+
edition = "2021"
65

76
[dependencies]
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
[package]
22
name = "restaurant"
33
version = "0.1.0"
4-
authors = ["Your Name <you@example.com>"]
5-
edition = "2018"
4+
edition = "2021"
65

76
[dependencies]
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
[package]
22
name = "restaurant"
33
version = "0.1.0"
4-
authors = ["Your Name <you@example.com>"]
5-
edition = "2018"
4+
edition = "2021"
65

76
[dependencies]
Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// ANCHOR: here
21
mod front_of_house {
32
pub mod hosting {
43
pub fn add_to_waitlist() {}
@@ -9,9 +8,4 @@ pub use crate::front_of_house::hosting;
98

109
pub fn eat_at_restaurant() {
1110
hosting::add_to_waitlist();
12-
hosting::add_to_waitlist();
13-
hosting::add_to_waitlist();
1411
}
15-
// ANCHOR_END: here
16-
17-
fn main() {}

0 commit comments

Comments
 (0)