Skip to content

Commit 7dce9e1

Browse files
committed
ch05 構造体を使用して関係のあるデータを構造化するの和訳を最新版に更新
rust-lang/book@19c40bf
1 parent 005ab57 commit 7dce9e1

File tree

66 files changed

+973
-774
lines changed

Some content is hidden

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

66 files changed

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

76
[dependencies]

listings/ch05-using-structs-to-structure-related-data/listing-05-01/src/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
// ANCHOR: here
22
struct User {
3+
active: bool,
34
username: String,
45
email: String,
56
sign_in_count: u64,
6-
active: bool,
77
}
88
// ANCHOR_END: here
99

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

76
[dependencies]
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
struct User {
2+
active: bool,
23
username: String,
34
email: String,
45
sign_in_count: u64,
5-
active: bool,
66
}
77

8+
// ANCHOR: here
89
fn main() {
9-
// ANCHOR: here
1010
let user1 = User {
11-
email: String::from("[email protected]"),
12-
username: String::from("someusername123"),
1311
active: true,
12+
username: String::from("someusername123"),
13+
email: String::from("[email protected]"),
1414
sign_in_count: 1,
1515
};
16-
// ANCHOR_END: here
1716
}
17+
// ANCHOR_END: here
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
[package]
22
name = "structs"
33
version = "0.1.0"
4-
authors = ["Your Name <[email protected]>"]
5-
edition = "2018"
4+
edition = "2021"
65

76
[dependencies]
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
struct User {
2+
active: bool,
23
username: String,
34
email: String,
45
sign_in_count: u64,
5-
active: bool,
66
}
77

8+
// ANCHOR: here
89
fn main() {
9-
// ANCHOR: here
1010
let mut user1 = User {
11-
email: String::from("[email protected]"),
12-
username: String::from("someusername123"),
1311
active: true,
12+
username: String::from("someusername123"),
13+
email: String::from("[email protected]"),
1414
sign_in_count: 1,
1515
};
1616

1717
user1.email = String::from("[email protected]");
18-
// ANCHOR_END: here
1918
}
19+
// ANCHOR_END: here
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
[package]
22
name = "structs"
33
version = "0.1.0"
4-
authors = ["Your Name <[email protected]>"]
5-
edition = "2018"
4+
edition = "2021"
65

76
[dependencies]

listings/ch05-using-structs-to-structure-related-data/listing-05-04/src/main.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
struct User {
2+
active: bool,
23
username: String,
34
email: String,
45
sign_in_count: u64,
5-
active: bool,
66
}
77

88
// ANCHOR: here
99
fn build_user(email: String, username: String) -> User {
1010
User {
11-
email: email,
12-
username: username,
1311
active: true,
12+
username: username,
13+
email: email,
1414
sign_in_count: 1,
1515
}
1616
}
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
[package]
22
name = "structs"
33
version = "0.1.0"
4-
authors = ["Your Name <[email protected]>"]
5-
edition = "2018"
4+
edition = "2021"
65

76
[dependencies]

listings/ch05-using-structs-to-structure-related-data/listing-05-05/src/main.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
struct User {
2+
active: bool,
23
username: String,
34
email: String,
45
sign_in_count: u64,
5-
active: bool,
66
}
77

88
// ANCHOR: here
99
fn build_user(email: String, username: String) -> User {
1010
User {
11-
email,
12-
username,
1311
active: true,
12+
username,
13+
email,
1414
sign_in_count: 1,
1515
}
1616
}
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
[package]
22
name = "structs"
33
version = "0.1.0"
4-
authors = ["Your Name <[email protected]>"]
5-
edition = "2018"
4+
edition = "2021"
65

76
[dependencies]
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,28 @@
11
struct User {
2+
active: bool,
23
username: String,
34
email: String,
45
sign_in_count: u64,
5-
active: bool,
66
}
77

8+
// ANCHOR: here
89
fn main() {
10+
// --snip--
11+
// ANCHOR_END: here
12+
913
let user1 = User {
1014
email: String::from("[email protected]"),
1115
username: String::from("someusername123"),
1216
active: true,
1317
sign_in_count: 1,
1418
};
15-
1619
// ANCHOR: here
20+
1721
let user2 = User {
18-
email: String::from("[email protected]"),
19-
username: String::from("anotherusername567"),
2022
active: user1.active,
23+
username: user1.username,
24+
email: String::from("[email protected]"),
2125
sign_in_count: user1.sign_in_count,
2226
};
23-
// ANCHOR_END: here
2427
}
28+
// ANCHOR_END: here
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
[package]
22
name = "structs"
33
version = "0.1.0"
4-
authors = ["Your Name <[email protected]>"]
5-
edition = "2018"
4+
edition = "2021"
65

76
[dependencies]
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,26 @@
11
struct User {
2+
active: bool,
23
username: String,
34
email: String,
45
sign_in_count: u64,
5-
active: bool,
66
}
77

8+
// ANCHOR: here
89
fn main() {
10+
// --snip--
11+
// ANCHOR_END: here
12+
913
let user1 = User {
1014
email: String::from("[email protected]"),
1115
username: String::from("someusername123"),
1216
active: true,
1317
sign_in_count: 1,
1418
};
15-
1619
// ANCHOR: here
20+
1721
let user2 = User {
1822
email: String::from("[email protected]"),
19-
username: String::from("anotherusername567"),
2023
..user1
2124
};
22-
// ANCHOR_END: here
2325
}
26+
// ANCHOR_END: here

listings/ch05-using-structs-to-structure-related-data/listing-05-08/Cargo.lock

+1-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
[package]
2-
name = "structs"
2+
name = "rectangles"
33
version = "0.1.0"
4-
authors = ["Your Name <[email protected]>"]
5-
edition = "2018"
4+
edition = "2021"
65

76
[dependencies]
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
$ cargo run
2-
Compiling structs v0.1.0 (file:///projects/structs)
2+
Compiling rectangles v0.1.0 (file:///projects/rectangles)
33
Finished dev [unoptimized + debuginfo] target(s) in 0.42s
4-
Running `target/debug/structs`
4+
Running `target/debug/rectangles`
55
The area of the rectangle is 1500 square pixels.
6+
(長方形の面積は、1500平方ピクセルです)

listings/ch05-using-structs-to-structure-related-data/listing-05-08/src/main.rs

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ fn main() {
44
let height1 = 50;
55

66
println!(
7+
// 長方形の面積は、{}平方ピクセルです
78
"The area of the rectangle is {} square pixels.",
89
area(width1, height1)
910
);

listings/ch05-using-structs-to-structure-related-data/listing-05-09/Cargo.lock

+1-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
[package]
2-
name = "structs"
2+
name = "rectangles"
33
version = "0.1.0"
4-
authors = ["Your Name <[email protected]>"]
5-
edition = "2018"
4+
edition = "2021"
65

76
[dependencies]

listings/ch05-using-structs-to-structure-related-data/listing-05-10/Cargo.lock

+1-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
[package]
2-
name = "structs"
2+
name = "rectangles"
33
version = "0.1.0"
4-
authors = ["Your Name <[email protected]>"]
5-
edition = "2018"
4+
edition = "2021"
65

76
[dependencies]

listings/ch05-using-structs-to-structure-related-data/listing-05-11/Cargo.lock

+1-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
[package]
2-
name = "structs"
2+
name = "rectangles"
33
version = "0.1.0"
4-
authors = ["Your Name <[email protected]>"]
5-
edition = "2018"
4+
edition = "2021"
65

76
[dependencies]
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
$ cargo run
2-
Compiling structs v0.1.0 (file:///projects/structs)
2+
Compiling rectangles v0.1.0 (file:///projects/rectangles)
33
error[E0277]: `Rectangle` doesn't implement `std::fmt::Display`
4+
(エラー: `Rectangle`は`std::fmt::Display`を実装していません)
45
--> src/main.rs:12:29
56
|
67
12 | println!("rect1 is {}", rect1);
78
| ^^^^^ `Rectangle` cannot be formatted with the default formatter
89
|
910
= help: the trait `std::fmt::Display` is not implemented for `Rectangle`
1011
= note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead
11-
= note: required by `std::fmt::Display::fmt`
12-
13-
error: aborting due to previous error
12+
(ヘルプ: `std::fmt::Display`は`Rectangle`に対して実装されていません)
13+
(注釈: フォーマット文字列では代わりに`{:?}`(またはpretty-printするためには{:#?})が使用できるかもしれません)
14+
= 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)
1415

1516
For more information about this error, try `rustc --explain E0277`.
16-
error: could not compile `structs`.
17-
18-
To learn more, run the command again with --verbose.
17+
error: could not compile `rectangles` (bin "rectangles") due to 1 previous error

listings/ch05-using-structs-to-structure-related-data/listing-05-11/src/main.rs

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

12+
// rect1は{}です
1213
println!("rect1 is {}", rect1);
1314
}

listings/ch05-using-structs-to-structure-related-data/listing-05-12/Cargo.lock

+1-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
[package]
2-
name = "structs"
2+
name = "rectangles"
33
version = "0.1.0"
4-
authors = ["Your Name <[email protected]>"]
5-
edition = "2018"
4+
edition = "2021"
65

76
[dependencies]
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
$ cargo run
2-
Compiling structs v0.1.0 (file:///projects/structs)
2+
Compiling rectangles v0.1.0 (file:///projects/rectangles)
33
Finished dev [unoptimized + debuginfo] target(s) in 0.48s
4-
Running `target/debug/structs`
4+
Running `target/debug/rectangles`
55
rect1 is Rectangle { width: 30, height: 50 }

listings/ch05-using-structs-to-structure-related-data/listing-05-13/Cargo.lock

+1-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
[package]
2-
name = "structs"
2+
name = "rectangles"
33
version = "0.1.0"
4-
authors = ["Your Name <[email protected]>"]
5-
edition = "2018"
4+
edition = "2021"
65

76
[dependencies]

listings/ch05-using-structs-to-structure-related-data/listing-05-13/src/main.rs

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ fn main() {
1717
};
1818

1919
println!(
20+
// 長方形の面積は{}平方ピクセルです。
2021
"The area of the rectangle is {} square pixels.",
2122
rect1.area()
2223
);

0 commit comments

Comments
 (0)