Skip to content

Commit d61d23d

Browse files
committed
ch17 Rustのオブジェクト指向プログラミング機能の和訳を最新版に更新
rust-lang/book@19c40bf
1 parent b7f9baf commit d61d23d

File tree

37 files changed

+410
-888
lines changed

37 files changed

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

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

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

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

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

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

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

76
[dependencies]

listings/ch17-oop/listing-17-07/src/lib.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ pub struct Button {
2424
impl Draw for Button {
2525
fn draw(&self) {
2626
// code to actually draw a button
27+
// 実際にボタンを描画するコード
2728
}
2829
}
2930
// ANCHOR_END: here
30-
31-
fn main() {}
+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
[package]
22
name = "gui"
33
version = "0.1.0"
4-
authors = ["Your Name <[email protected]>"]
5-
edition = "2018"
4+
edition = "2021"
65

76
[dependencies]

listings/ch17-oop/listing-17-08/src/main.rs

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ struct SelectBox {
1010
impl Draw for SelectBox {
1111
fn draw(&self) {
1212
// code to actually draw a select box
13+
//セレクトボックスを実際に描画するコード
1314
}
1415
}
1516
// ANCHOR_END: here
+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
[package]
22
name = "gui"
33
version = "0.1.0"
4-
authors = ["Your Name <[email protected]>"]
5-
edition = "2018"
4+
edition = "2021"
65

76
[dependencies]

listings/ch17-oop/listing-17-09/src/main.rs

+3
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,11 @@ fn main() {
2222
width: 75,
2323
height: 10,
2424
options: vec![
25+
// はい
2526
String::from("Yes"),
27+
// 多分
2628
String::from("Maybe"),
29+
// いいえ
2730
String::from("No"),
2831
],
2932
}),
+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
[package]
22
name = "gui"
33
version = "0.1.0"
4-
authors = ["Your Name <[email protected]>"]
5-
edition = "2018"
4+
edition = "2021"
65

76
[dependencies]
+5-8
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
$ cargo run
22
Compiling gui v0.1.0 (file:///projects/gui)
3-
error[E0277]: the trait bound `std::string::String: gui::Draw` is not satisfied
3+
error[E0277]: the trait bound `String: Draw` is not satisfied
44
--> src/main.rs:5:26
55
|
66
5 | components: vec![Box::new(String::from("Hi"))],
7-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `gui::Draw` is not implemented for `std::string::String`
7+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Draw` is not implemented for `String`
88
|
9-
= note: required for the cast to the object type `dyn gui::Draw`
10-
11-
error: aborting due to previous error
9+
= help: the trait `Draw` is implemented for `Button`
10+
= note: required for the cast from `Box<String>` to `Box<dyn Draw>`
1211

1312
For more information about this error, try `rustc --explain E0277`.
14-
error: could not compile `gui`.
15-
16-
To learn more, run the command again with --verbose.
13+
error: could not compile `gui` (bin "gui") due to 1 previous error
+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
[package]
22
name = "blog"
33
version = "0.1.0"
4-
authors = ["Your Name <[email protected]>"]
5-
edition = "2018"
4+
edition = "2021"
65

76
[dependencies]

listings/ch17-oop/listing-17-11/src/main.rs

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use blog::Post;
55
fn main() {
66
let mut post = Post::new();
77

8+
// "今日はお昼にサラダを食べた"
89
post.add_text("I ate a salad for lunch today");
910
assert_eq!("", post.content());
1011
// ANCHOR_END: here
+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
[package]
22
name = "blog"
33
version = "0.1.0"
4-
authors = ["Your Name <[email protected]>"]
5-
edition = "2018"
4+
edition = "2021"
65

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

76
[dependencies]

listings/ch17-oop/listing-17-13/src/lib.rs

-2
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,3 @@ trait State {}
2626
struct Draft {}
2727

2828
impl State for Draft {}
29-
30-
fn main() {}
+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
[package]
22
name = "blog"
33
version = "0.1.0"
4-
authors = ["Your Name <[email protected]>"]
5-
edition = "2018"
4+
edition = "2021"
65

76
[dependencies]

listings/ch17-oop/listing-17-14/src/lib.rs

-2
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,3 @@ trait State {}
3030
struct Draft {}
3131

3232
impl State for Draft {}
33-
34-
fn main() {}
+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
[package]
22
name = "blog"
33
version = "0.1.0"
4-
authors = ["Your Name <[email protected]>"]
5-
edition = "2018"
4+
edition = "2021"
65

76
[dependencies]

listings/ch17-oop/listing-17-15/src/lib.rs

-2
Original file line numberDiff line numberDiff line change
@@ -50,5 +50,3 @@ impl State for PendingReview {
5050
}
5151
}
5252
// ANCHOR_END: here
53-
54-
fn main() {}
+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
[package]
22
name = "blog"
33
version = "0.1.0"
4-
authors = ["Your Name <[email protected]>"]
5-
edition = "2018"
4+
edition = "2021"
65

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

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

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

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

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

76
[dependencies]

listings/ch17-oop/no-listing-01-trait-object-of-clone/Cargo.lock

-6
This file was deleted.

listings/ch17-oop/no-listing-01-trait-object-of-clone/Cargo.toml

-7
This file was deleted.

listings/ch17-oop/no-listing-01-trait-object-of-clone/output.txt

-16
This file was deleted.

listings/ch17-oop/no-listing-01-trait-object-of-clone/src/lib.rs

-3
This file was deleted.

src/ch17-00-oop.md

+16-16
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,24 @@
55
# Rustのオブジェクト指向プログラミング機能
66

77
<!--
8-
Object-oriented programming (OOP) is a way of modeling programs. Objects came
9-
from Simula in the 1960s. Those objects influenced Alan Kay’s programming
10-
architecture in which objects pass messages to each other. He coined the term
11-
*object-oriented programming* in 1967 to describe this architecture. Many
12-
competing definitions describe what OOP is; some definitions would classify
13-
Rust as object oriented, but other definitions would not. In this chapter,
14-
we'll explore certain characteristics that are commonly considered object
15-
oriented and how those characteristics translate to idiomatic Rust. We’ll then
16-
show you how to implement an object-oriented design pattern in Rust and discuss
17-
the trade-offs of doing so versus implementing a solution using some of Rust’s
18-
strengths instead.
8+
Object-oriented programming (OOP) is a way of modeling programs. Objects as a
9+
programmatic concept were introduced in the programming language Simula in the
10+
1960s. Those objects influenced Alan Kay’s programming architecture in which
11+
objects pass messages to each other. To describe this architecture, he coined
12+
the term *object-oriented programming* in 1967. Many competing definitions
13+
describe what OOP is, and by some of these definitions Rust is object-oriented,
14+
but by others it is not. In this chapter, we’ll explore certain characteristics
15+
that are commonly considered object-oriented and how those characteristics
16+
translate to idiomatic Rust. We’ll then show you how to implement an
17+
object-oriented design pattern in Rust and discuss the trade-offs of doing so
18+
versus implementing a solution using some of Rust’s strengths instead.
1919
-->
2020

21-
オブジェクト指向プログラミング(OOP)は、プログラムをモデル化する手段です。オブジェクトは
22-
1960年代のSimulaに端緒を発しています。このオブジェクトは、
21+
オブジェクト指向プログラミング(OOP)は、プログラムをモデル化する手段です。プログラム上の概念としてのオブジェクトは
22+
1960年代のプログラミング言語Simulaで導入されました。このオブジェクトは、
2323
お互いにメッセージを渡し合うというアラン・ケイ(Alan Kay)のプログラミングアーキテクチャに影響を及ぼしました。
24-
彼は、このアーキテクチャを解説するために*オブジェクト指向プログラミング*という用語を造語しました。
25-
多くの競合する定義がOOPが何かを解説しています; Rustをオブジェクト指向と区分する定義もありますし、
26-
しない定義もあります。この章では、広くオブジェクト指向と捉えられる特定の特徴と、
24+
彼は、このアーキテクチャを記述するために*オブジェクト指向プログラミング*という用語を造語しました。
25+
多くの競合する定義がOOPが何かを記述しており、こうした定義の一部によれば、Rustはオブジェクト指向であり
26+
他の定義によれば、Rustはオブジェクト指向ではありません。この章では、広くオブジェクト指向と捉えられる特定の特徴と、
2727
それらの特徴がこなれたRustでどう表現されるかを探究します。それからオブジェクト指向のデザインパターンをRustで実装する方法を示し、
2828
そうすることとRustの強みを活用して代わりの解決策を実装する方法の代償を議論します。

0 commit comments

Comments
 (0)