Skip to content

Commit

Permalink
ch17 Rustのオブジェクト指向プログラミング機能の和訳を最新版に更新
Browse files Browse the repository at this point in the history
  • Loading branch information
shinmili committed Feb 4, 2025
1 parent 64432c2 commit bd648eb
Show file tree
Hide file tree
Showing 37 changed files with 410 additions and 888 deletions.
3 changes: 1 addition & 2 deletions listings/ch17-oop/listing-17-01/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[package]
name = "averaged-collection"
version = "0.1.0"
authors = ["Your Name <[email protected]>"]
edition = "2018"
edition = "2021"

[dependencies]
3 changes: 1 addition & 2 deletions listings/ch17-oop/listing-17-02/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[package]
name = "averaged-collection"
version = "0.1.0"
authors = ["Your Name <[email protected]>"]
edition = "2018"
edition = "2021"

[dependencies]
3 changes: 1 addition & 2 deletions listings/ch17-oop/listing-17-03/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[package]
name = "gui"
version = "0.1.0"
authors = ["Your Name <[email protected]>"]
edition = "2018"
edition = "2021"

[dependencies]
3 changes: 1 addition & 2 deletions listings/ch17-oop/listing-17-04/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[package]
name = "gui"
version = "0.1.0"
authors = ["Your Name <[email protected]>"]
edition = "2018"
edition = "2021"

[dependencies]
3 changes: 1 addition & 2 deletions listings/ch17-oop/listing-17-05/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[package]
name = "gui"
version = "0.1.0"
authors = ["Your Name <[email protected]>"]
edition = "2018"
edition = "2021"

[dependencies]
3 changes: 1 addition & 2 deletions listings/ch17-oop/listing-17-06/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[package]
name = "gui"
version = "0.1.0"
authors = ["Your Name <[email protected]>"]
edition = "2018"
edition = "2021"

[dependencies]
3 changes: 1 addition & 2 deletions listings/ch17-oop/listing-17-07/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[package]
name = "gui"
version = "0.1.0"
authors = ["Your Name <[email protected]>"]
edition = "2018"
edition = "2021"

[dependencies]
3 changes: 1 addition & 2 deletions listings/ch17-oop/listing-17-07/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ pub struct Button {
impl Draw for Button {
fn draw(&self) {
// code to actually draw a button
// 実際にボタンを描画するコード
}
}
// ANCHOR_END: here

fn main() {}
3 changes: 1 addition & 2 deletions listings/ch17-oop/listing-17-08/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[package]
name = "gui"
version = "0.1.0"
authors = ["Your Name <[email protected]>"]
edition = "2018"
edition = "2021"

[dependencies]
1 change: 1 addition & 0 deletions listings/ch17-oop/listing-17-08/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ struct SelectBox {
impl Draw for SelectBox {
fn draw(&self) {
// code to actually draw a select box
//セレクトボックスを実際に描画するコード
}
}
// ANCHOR_END: here
Expand Down
3 changes: 1 addition & 2 deletions listings/ch17-oop/listing-17-09/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[package]
name = "gui"
version = "0.1.0"
authors = ["Your Name <[email protected]>"]
edition = "2018"
edition = "2021"

[dependencies]
3 changes: 3 additions & 0 deletions listings/ch17-oop/listing-17-09/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,11 @@ fn main() {
width: 75,
height: 10,
options: vec![
// はい
String::from("Yes"),
// 多分
String::from("Maybe"),
// いいえ
String::from("No"),
],
}),
Expand Down
3 changes: 1 addition & 2 deletions listings/ch17-oop/listing-17-10/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[package]
name = "gui"
version = "0.1.0"
authors = ["Your Name <[email protected]>"]
edition = "2018"
edition = "2021"

[dependencies]
13 changes: 5 additions & 8 deletions listings/ch17-oop/listing-17-10/output.txt
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
$ cargo run
Compiling gui v0.1.0 (file:///projects/gui)
error[E0277]: the trait bound `std::string::String: gui::Draw` is not satisfied
error[E0277]: the trait bound `String: Draw` is not satisfied
--> src/main.rs:5:26
|
5 | components: vec![Box::new(String::from("Hi"))],
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `gui::Draw` is not implemented for `std::string::String`
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Draw` is not implemented for `String`
|
= note: required for the cast to the object type `dyn gui::Draw`

error: aborting due to previous error
= help: the trait `Draw` is implemented for `Button`
= note: required for the cast from `Box<String>` to `Box<dyn Draw>`

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

To learn more, run the command again with --verbose.
error: could not compile `gui` (bin "gui") due to 1 previous error
3 changes: 1 addition & 2 deletions listings/ch17-oop/listing-17-11/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[package]
name = "blog"
version = "0.1.0"
authors = ["Your Name <[email protected]>"]
edition = "2018"
edition = "2021"

[dependencies]
1 change: 1 addition & 0 deletions listings/ch17-oop/listing-17-11/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use blog::Post;
fn main() {
let mut post = Post::new();

// "今日はお昼にサラダを食べた"
post.add_text("I ate a salad for lunch today");
assert_eq!("", post.content());
// ANCHOR_END: here
Expand Down
3 changes: 1 addition & 2 deletions listings/ch17-oop/listing-17-12/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[package]
name = "blog"
version = "0.1.0"
authors = ["Your Name <[email protected]>"]
edition = "2018"
edition = "2021"

[dependencies]
3 changes: 1 addition & 2 deletions listings/ch17-oop/listing-17-13/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[package]
name = "blog"
version = "0.1.0"
authors = ["Your Name <[email protected]>"]
edition = "2018"
edition = "2021"

[dependencies]
2 changes: 0 additions & 2 deletions listings/ch17-oop/listing-17-13/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,3 @@ trait State {}
struct Draft {}

impl State for Draft {}

fn main() {}
3 changes: 1 addition & 2 deletions listings/ch17-oop/listing-17-14/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[package]
name = "blog"
version = "0.1.0"
authors = ["Your Name <[email protected]>"]
edition = "2018"
edition = "2021"

[dependencies]
2 changes: 0 additions & 2 deletions listings/ch17-oop/listing-17-14/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,3 @@ trait State {}
struct Draft {}

impl State for Draft {}

fn main() {}
3 changes: 1 addition & 2 deletions listings/ch17-oop/listing-17-15/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[package]
name = "blog"
version = "0.1.0"
authors = ["Your Name <[email protected]>"]
edition = "2018"
edition = "2021"

[dependencies]
2 changes: 0 additions & 2 deletions listings/ch17-oop/listing-17-15/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,3 @@ impl State for PendingReview {
}
}
// ANCHOR_END: here

fn main() {}
3 changes: 1 addition & 2 deletions listings/ch17-oop/listing-17-16/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[package]
name = "blog"
version = "0.1.0"
authors = ["Your Name <[email protected]>"]
edition = "2018"
edition = "2021"

[dependencies]
3 changes: 1 addition & 2 deletions listings/ch17-oop/listing-17-17/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[package]
name = "blog"
version = "0.1.0"
authors = ["Your Name <[email protected]>"]
edition = "2018"
edition = "2021"

[dependencies]
3 changes: 1 addition & 2 deletions listings/ch17-oop/listing-17-18/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[package]
name = "blog"
version = "0.1.0"
authors = ["Your Name <[email protected]>"]
edition = "2018"
edition = "2021"

[dependencies]
3 changes: 1 addition & 2 deletions listings/ch17-oop/listing-17-19/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[package]
name = "blog"
version = "0.1.0"
authors = ["Your Name <[email protected]>"]
edition = "2018"
edition = "2021"

[dependencies]
3 changes: 1 addition & 2 deletions listings/ch17-oop/listing-17-20/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[package]
name = "blog"
version = "0.1.0"
authors = ["Your Name <[email protected]>"]
edition = "2018"
edition = "2021"

[dependencies]
3 changes: 1 addition & 2 deletions listings/ch17-oop/listing-17-21/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[package]
name = "blog"
version = "0.1.0"
authors = ["Your Name <[email protected]>"]
edition = "2018"
edition = "2021"

[dependencies]

This file was deleted.

This file was deleted.

16 changes: 0 additions & 16 deletions listings/ch17-oop/no-listing-01-trait-object-of-clone/output.txt

This file was deleted.

This file was deleted.

32 changes: 16 additions & 16 deletions src/ch17-00-oop.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,24 @@
# Rustのオブジェクト指向プログラミング機能

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

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

0 comments on commit bd648eb

Please sign in to comment.