summaryrefslogtreecommitdiffstats
path: root/src/doc/book/listings/ch17-oop/listing-17-19
diff options
context:
space:
mode:
Diffstat (limited to 'src/doc/book/listings/ch17-oop/listing-17-19')
-rw-r--r--src/doc/book/listings/ch17-oop/listing-17-19/Cargo.lock6
-rw-r--r--src/doc/book/listings/ch17-oop/listing-17-19/Cargo.toml6
-rw-r--r--src/doc/book/listings/ch17-oop/listing-17-19/src/lib.rs25
3 files changed, 37 insertions, 0 deletions
diff --git a/src/doc/book/listings/ch17-oop/listing-17-19/Cargo.lock b/src/doc/book/listings/ch17-oop/listing-17-19/Cargo.lock
new file mode 100644
index 000000000..b6f4232c6
--- /dev/null
+++ b/src/doc/book/listings/ch17-oop/listing-17-19/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-19/Cargo.toml b/src/doc/book/listings/ch17-oop/listing-17-19/Cargo.toml
new file mode 100644
index 000000000..1619af5c6
--- /dev/null
+++ b/src/doc/book/listings/ch17-oop/listing-17-19/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-19/src/lib.rs b/src/doc/book/listings/ch17-oop/listing-17-19/src/lib.rs
new file mode 100644
index 000000000..bfe034eaf
--- /dev/null
+++ b/src/doc/book/listings/ch17-oop/listing-17-19/src/lib.rs
@@ -0,0 +1,25 @@
+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
+ }
+}
+
+impl DraftPost {
+ pub fn add_text(&mut self, text: &str) {
+ self.content.push_str(text);
+ }
+}