diff --git a/ci/dictionary.txt b/ci/dictionary.txt index ba46cfdd32..3ce0ea7d31 100644 --- a/ci/dictionary.txt +++ b/ci/dictionary.txt @@ -442,6 +442,7 @@ reformats refutability reimplement RemAssign +repost repr representable request's @@ -487,6 +488,7 @@ sizeof SliceIndex Smalltalk snuck +SocialPost someproject SomeType someusername diff --git a/listings/ch10-generic-types-traits-and-lifetimes/listing-10-13/src/lib.rs b/listings/ch10-generic-types-traits-and-lifetimes/listing-10-13/src/lib.rs index c4c83329ef..cbf66ab27a 100644 --- a/listings/ch10-generic-types-traits-and-lifetimes/listing-10-13/src/lib.rs +++ b/listings/ch10-generic-types-traits-and-lifetimes/listing-10-13/src/lib.rs @@ -16,14 +16,14 @@ impl Summary for NewsArticle { } } -pub struct Tweet { +pub struct SocialPost { pub username: String, pub content: String, pub reply: bool, - pub retweet: bool, + pub repost: bool, } -impl Summary for Tweet { +impl Summary for SocialPost { fn summarize(&self) -> String { format!("{}: {}", self.username, self.content) } diff --git a/listings/ch10-generic-types-traits-and-lifetimes/listing-10-14/src/lib.rs b/listings/ch10-generic-types-traits-and-lifetimes/listing-10-14/src/lib.rs index fb59b84fb1..d64ea00729 100644 --- a/listings/ch10-generic-types-traits-and-lifetimes/listing-10-14/src/lib.rs +++ b/listings/ch10-generic-types-traits-and-lifetimes/listing-10-14/src/lib.rs @@ -15,14 +15,14 @@ pub struct NewsArticle { impl Summary for NewsArticle {} -pub struct Tweet { +pub struct SocialPost { pub username: String, pub content: String, pub reply: bool, - pub retweet: bool, + pub repost: bool, } -impl Summary for Tweet { +impl Summary for SocialPost { fn summarize(&self) -> String { format!("{}: {}", self.username, self.content) } diff --git a/listings/ch10-generic-types-traits-and-lifetimes/no-listing-01-calling-trait-method/src/lib.rs b/listings/ch10-generic-types-traits-and-lifetimes/no-listing-01-calling-trait-method/src/lib.rs index fa644ca4fb..1036ff9016 100644 --- a/listings/ch10-generic-types-traits-and-lifetimes/no-listing-01-calling-trait-method/src/lib.rs +++ b/listings/ch10-generic-types-traits-and-lifetimes/no-listing-01-calling-trait-method/src/lib.rs @@ -15,14 +15,14 @@ impl Summary for NewsArticle { } } -pub struct Tweet { +pub struct SocialPost { pub username: String, pub content: String, pub reply: bool, - pub retweet: bool, + pub repost: bool, } -impl Summary for Tweet { +impl Summary for SocialPost { fn summarize(&self) -> String { format!("{}: {}", self.username, self.content) } diff --git a/listings/ch10-generic-types-traits-and-lifetimes/no-listing-01-calling-trait-method/src/main.rs b/listings/ch10-generic-types-traits-and-lifetimes/no-listing-01-calling-trait-method/src/main.rs index 0b51121d94..0363b3ed3e 100644 --- a/listings/ch10-generic-types-traits-and-lifetimes/no-listing-01-calling-trait-method/src/main.rs +++ b/listings/ch10-generic-types-traits-and-lifetimes/no-listing-01-calling-trait-method/src/main.rs @@ -1,14 +1,14 @@ -use aggregator::{Summary, Tweet}; +use aggregator::{SocialPost, Summary}; fn main() { - let tweet = Tweet { + let post = SocialPost { username: String::from("horse_ebooks"), content: String::from( "of course, as you probably already know, people", ), reply: false, - retweet: false, + repost: false, }; - println!("1 new tweet: {}", tweet.summarize()); + println!("1 new social post: {}", post.summarize()); } diff --git a/listings/ch10-generic-types-traits-and-lifetimes/no-listing-02-calling-default-impl/src/lib.rs b/listings/ch10-generic-types-traits-and-lifetimes/no-listing-02-calling-default-impl/src/lib.rs index b6f93a68f7..d0abd43f04 100644 --- a/listings/ch10-generic-types-traits-and-lifetimes/no-listing-02-calling-default-impl/src/lib.rs +++ b/listings/ch10-generic-types-traits-and-lifetimes/no-listing-02-calling-default-impl/src/lib.rs @@ -13,14 +13,14 @@ pub struct NewsArticle { impl Summary for NewsArticle {} -pub struct Tweet { +pub struct SocialPost { pub username: String, pub content: String, pub reply: bool, - pub retweet: bool, + pub repost: bool, } -impl Summary for Tweet { +impl Summary for SocialPost { fn summarize(&self) -> String { format!("{}: {}", self.username, self.content) } diff --git a/listings/ch10-generic-types-traits-and-lifetimes/no-listing-03-default-impl-calls-other-methods/src/lib.rs b/listings/ch10-generic-types-traits-and-lifetimes/no-listing-03-default-impl-calls-other-methods/src/lib.rs index 643906f691..dac17fc144 100644 --- a/listings/ch10-generic-types-traits-and-lifetimes/no-listing-03-default-impl-calls-other-methods/src/lib.rs +++ b/listings/ch10-generic-types-traits-and-lifetimes/no-listing-03-default-impl-calls-other-methods/src/lib.rs @@ -8,15 +8,15 @@ pub trait Summary { } // ANCHOR_END: here -pub struct Tweet { +pub struct SocialPost { pub username: String, pub content: String, pub reply: bool, - pub retweet: bool, + pub repost: bool, } // ANCHOR: impl -impl Summary for Tweet { +impl Summary for SocialPost { fn summarize_author(&self) -> String { format!("@{}", self.username) } diff --git a/listings/ch10-generic-types-traits-and-lifetimes/no-listing-03-default-impl-calls-other-methods/src/main.rs b/listings/ch10-generic-types-traits-and-lifetimes/no-listing-03-default-impl-calls-other-methods/src/main.rs index e05e8e1c67..5247f7851b 100644 --- a/listings/ch10-generic-types-traits-and-lifetimes/no-listing-03-default-impl-calls-other-methods/src/main.rs +++ b/listings/ch10-generic-types-traits-and-lifetimes/no-listing-03-default-impl-calls-other-methods/src/main.rs @@ -1,16 +1,16 @@ -use aggregator::{self, Summary, Tweet}; +use aggregator::{self, SocialPost, Summary}; fn main() { // ANCHOR: here - let tweet = Tweet { + let post = SocialPost { username: String::from("horse_ebooks"), content: String::from( "of course, as you probably already know, people", ), reply: false, - retweet: false, + repost: false, }; - println!("1 new tweet: {}", tweet.summarize()); + println!("1 new social post: {}", post.summarize()); // ANCHOR_END: here } diff --git a/listings/ch10-generic-types-traits-and-lifetimes/no-listing-04-traits-as-parameters/src/lib.rs b/listings/ch10-generic-types-traits-and-lifetimes/no-listing-04-traits-as-parameters/src/lib.rs index 2619943515..18a8ddbfd2 100644 --- a/listings/ch10-generic-types-traits-and-lifetimes/no-listing-04-traits-as-parameters/src/lib.rs +++ b/listings/ch10-generic-types-traits-and-lifetimes/no-listing-04-traits-as-parameters/src/lib.rs @@ -15,14 +15,14 @@ impl Summary for NewsArticle { } } -pub struct Tweet { +pub struct SocialPost { pub username: String, pub content: String, pub reply: bool, - pub retweet: bool, + pub repost: bool, } -impl Summary for Tweet { +impl Summary for SocialPost { fn summarize(&self) -> String { format!("{}: {}", self.username, self.content) } diff --git a/listings/ch10-generic-types-traits-and-lifetimes/no-listing-05-returning-impl-trait/src/lib.rs b/listings/ch10-generic-types-traits-and-lifetimes/no-listing-05-returning-impl-trait/src/lib.rs index a611fce38e..a596c893d3 100644 --- a/listings/ch10-generic-types-traits-and-lifetimes/no-listing-05-returning-impl-trait/src/lib.rs +++ b/listings/ch10-generic-types-traits-and-lifetimes/no-listing-05-returning-impl-trait/src/lib.rs @@ -15,14 +15,14 @@ impl Summary for NewsArticle { } } -pub struct Tweet { +pub struct SocialPost { pub username: String, pub content: String, pub reply: bool, - pub retweet: bool, + pub repost: bool, } -impl Summary for Tweet { +impl Summary for SocialPost { fn summarize(&self) -> String { format!("{}: {}", self.username, self.content) } @@ -30,13 +30,13 @@ impl Summary for Tweet { // ANCHOR: here fn returns_summarizable() -> impl Summary { - Tweet { + SocialPost { username: String::from("horse_ebooks"), content: String::from( "of course, as you probably already know, people", ), reply: false, - retweet: false, + repost: false, } } // ANCHOR_END: here diff --git a/listings/ch10-generic-types-traits-and-lifetimes/no-listing-06-impl-trait-returns-one-type/src/lib.rs b/listings/ch10-generic-types-traits-and-lifetimes/no-listing-06-impl-trait-returns-one-type/src/lib.rs index 7cd81d4c32..a9ffbcdc79 100644 --- a/listings/ch10-generic-types-traits-and-lifetimes/no-listing-06-impl-trait-returns-one-type/src/lib.rs +++ b/listings/ch10-generic-types-traits-and-lifetimes/no-listing-06-impl-trait-returns-one-type/src/lib.rs @@ -15,14 +15,14 @@ impl Summary for NewsArticle { } } -pub struct Tweet { +pub struct SocialPost { pub username: String, pub content: String, pub reply: bool, - pub retweet: bool, + pub repost: bool, } -impl Summary for Tweet { +impl Summary for SocialPost { fn summarize(&self) -> String { format!("{}: {}", self.username, self.content) } @@ -43,13 +43,13 @@ fn returns_summarizable(switch: bool) -> impl Summary { ), } } else { - Tweet { + SocialPost { username: String::from("horse_ebooks"), content: String::from( "of course, as you probably already know, people", ), reply: false, - retweet: false, + repost: false, } } } diff --git a/src/ch10-02-traits.md b/src/ch10-02-traits.md index 5628eef64b..e853e9d757 100644 --- a/src/ch10-02-traits.md +++ b/src/ch10-02-traits.md @@ -17,15 +17,16 @@ define a set of behaviors necessary to accomplish some purpose. For example, let’s say we have multiple structs that hold various kinds and amounts of text: a `NewsArticle` struct that holds a news story filed in a -particular location and a `Tweet` that can have, at most, 280 characters along -with metadata that indicates whether it was a new tweet, a retweet, or a reply -to another tweet. +particular location and a `SocialPost` that can have, at most, 280 characters +along with metadata that indicates whether it was a new post, a repost, or a +reply to another post. We want to make a media aggregator library crate named `aggregator` that can -display summaries of data that might be stored in a `NewsArticle` or `Tweet` -instance. To do this, we need a summary from each type, and we’ll request that -summary by calling a `summarize` method on an instance. Listing 10-12 shows the -definition of a public `Summary` trait that expresses this behavior. +display summaries of data that might be stored in a `NewsArticle` or +`SocialPost` instance. To do this, we need a summary from each type, and we’ll +request that summary by calling a `summarize` method on an instance. Listing +10-12 shows the definition of a public `Summary` trait that expresses this +behavior.