summaryrefslogtreecommitdiffstats
path: root/src/doc/book/listings/ch17-oop/listing-17-20
diff options
context:
space:
mode:
Diffstat (limited to 'src/doc/book/listings/ch17-oop/listing-17-20')
-rw-r--r--src/doc/book/listings/ch17-oop/listing-17-20/Cargo.lock6
-rw-r--r--src/doc/book/listings/ch17-oop/listing-17-20/Cargo.toml6
-rw-r--r--src/doc/book/listings/ch17-oop/listing-17-20/src/lib.rs48
3 files changed, 60 insertions, 0 deletions
diff --git a/src/doc/book/listings/ch17-oop/listing-17-20/Cargo.lock b/src/doc/book/listings/ch17-oop/listing-17-20/Cargo.lock
new file mode 100644
index 000000000..b6f4232c6
--- /dev/null
+++ b/src/doc/book/listings/ch17-oop/listing-17-20/Cargo.lock
@@ -0,0 +1,6 @@
+# This file is automatically @generated by Cargo.
+# It is not intended for manual editing.
+[[package]]
+name = "blog"
+version = "0.1.0"
+
diff --git a/src/doc/book/listings/ch17-oop/listing-17-20/Cargo.toml b/src/doc/book/listings/ch17-oop/listing-17-20/Cargo.toml
new file mode 100644
index 000000000..1619af5c6
--- /dev/null
+++ b/src/doc/book/listings/ch17-oop/listing-17-20/Cargo.toml
@@ -0,0 +1,6 @@
+[package]
+name = "blog"
+version = "0.1.0"
+edition = "2021"
+
+[dependencies]
diff --git a/src/doc/book/listings/ch17-oop/listing-17-20/src/lib.rs b/src/doc/book/listings/ch17-oop/listing-17-20/src/lib.rs
new file mode 100644
index 000000000..3b82ec05d
--- /dev/null
+++ b/src/doc/book/listings/ch17-oop/listing-17-20/src/lib.rs
@@ -0,0 +1,48 @@
+pub struct Post {
+ content: String,
+}
+
+pub struct DraftPost {
+ content: String,
+}
+
+impl Post {
+ pub fn new() -> DraftPost {
+ DraftPost {
+ content: String::new(),
+ }
+ }
+
+ pub fn content(&self) -> &str {
+ &self.content
+ }
+}
+
+// ANCHOR: here
+impl DraftPost {
+ // --snip--
+ // ANCHOR_END: here
+ pub fn add_text(&mut self, text: &str) {
+ self.content.push_str(text);
+ }
+
+ // ANCHOR: here
+ pub fn request_review(self) -> PendingReviewPost {
+ PendingReviewPost {
+ content: self.content,
+ }
+ }
+}
+
+pub struct PendingReviewPost {
+ content: String,
+}
+
+impl PendingReviewPost {
+ pub fn approve(self) -> Post {
+ Post {
+ content: self.content,
+ }
+ }
+}
+// ANCHOR_END: here