Skip to content

Commit 81a976a

Browse files
authored
Merge pull request #4249 from rust-lang/social-media-discussion-generic
Ch. 10: Make social media discussion generic.
2 parents 0896670 + e5c8a0c commit 81a976a

File tree

12 files changed

+72
-67
lines changed

12 files changed

+72
-67
lines changed

ci/dictionary.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,7 @@ reformats
442442
refutability
443443
reimplement
444444
RemAssign
445+
repost
445446
repr
446447
representable
447448
request's
@@ -487,6 +488,7 @@ sizeof
487488
SliceIndex
488489
Smalltalk
489490
snuck
491+
SocialPost
490492
someproject
491493
SomeType
492494
someusername

listings/ch10-generic-types-traits-and-lifetimes/listing-10-13/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ impl Summary for NewsArticle {
1616
}
1717
}
1818

19-
pub struct Tweet {
19+
pub struct SocialPost {
2020
pub username: String,
2121
pub content: String,
2222
pub reply: bool,
23-
pub retweet: bool,
23+
pub repost: bool,
2424
}
2525

26-
impl Summary for Tweet {
26+
impl Summary for SocialPost {
2727
fn summarize(&self) -> String {
2828
format!("{}: {}", self.username, self.content)
2929
}

listings/ch10-generic-types-traits-and-lifetimes/listing-10-14/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ pub struct NewsArticle {
1515

1616
impl Summary for NewsArticle {}
1717

18-
pub struct Tweet {
18+
pub struct SocialPost {
1919
pub username: String,
2020
pub content: String,
2121
pub reply: bool,
22-
pub retweet: bool,
22+
pub repost: bool,
2323
}
2424

25-
impl Summary for Tweet {
25+
impl Summary for SocialPost {
2626
fn summarize(&self) -> String {
2727
format!("{}: {}", self.username, self.content)
2828
}

listings/ch10-generic-types-traits-and-lifetimes/no-listing-01-calling-trait-method/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ impl Summary for NewsArticle {
1515
}
1616
}
1717

18-
pub struct Tweet {
18+
pub struct SocialPost {
1919
pub username: String,
2020
pub content: String,
2121
pub reply: bool,
22-
pub retweet: bool,
22+
pub repost: bool,
2323
}
2424

25-
impl Summary for Tweet {
25+
impl Summary for SocialPost {
2626
fn summarize(&self) -> String {
2727
format!("{}: {}", self.username, self.content)
2828
}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
use aggregator::{Summary, Tweet};
1+
use aggregator::{SocialPost, Summary};
22

33
fn main() {
4-
let tweet = Tweet {
4+
let post = SocialPost {
55
username: String::from("horse_ebooks"),
66
content: String::from(
77
"of course, as you probably already know, people",
88
),
99
reply: false,
10-
retweet: false,
10+
repost: false,
1111
};
1212

13-
println!("1 new tweet: {}", tweet.summarize());
13+
println!("1 new social post: {}", post.summarize());
1414
}

listings/ch10-generic-types-traits-and-lifetimes/no-listing-02-calling-default-impl/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ pub struct NewsArticle {
1313

1414
impl Summary for NewsArticle {}
1515

16-
pub struct Tweet {
16+
pub struct SocialPost {
1717
pub username: String,
1818
pub content: String,
1919
pub reply: bool,
20-
pub retweet: bool,
20+
pub repost: bool,
2121
}
2222

23-
impl Summary for Tweet {
23+
impl Summary for SocialPost {
2424
fn summarize(&self) -> String {
2525
format!("{}: {}", self.username, self.content)
2626
}

listings/ch10-generic-types-traits-and-lifetimes/no-listing-03-default-impl-calls-other-methods/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ pub trait Summary {
88
}
99
// ANCHOR_END: here
1010

11-
pub struct Tweet {
11+
pub struct SocialPost {
1212
pub username: String,
1313
pub content: String,
1414
pub reply: bool,
15-
pub retweet: bool,
15+
pub repost: bool,
1616
}
1717

1818
// ANCHOR: impl
19-
impl Summary for Tweet {
19+
impl Summary for SocialPost {
2020
fn summarize_author(&self) -> String {
2121
format!("@{}", self.username)
2222
}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
use aggregator::{self, Summary, Tweet};
1+
use aggregator::{self, SocialPost, Summary};
22

33
fn main() {
44
// ANCHOR: here
5-
let tweet = Tweet {
5+
let post = SocialPost {
66
username: String::from("horse_ebooks"),
77
content: String::from(
88
"of course, as you probably already know, people",
99
),
1010
reply: false,
11-
retweet: false,
11+
repost: false,
1212
};
1313

14-
println!("1 new tweet: {}", tweet.summarize());
14+
println!("1 new social post: {}", post.summarize());
1515
// ANCHOR_END: here
1616
}

listings/ch10-generic-types-traits-and-lifetimes/no-listing-04-traits-as-parameters/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ impl Summary for NewsArticle {
1515
}
1616
}
1717

18-
pub struct Tweet {
18+
pub struct SocialPost {
1919
pub username: String,
2020
pub content: String,
2121
pub reply: bool,
22-
pub retweet: bool,
22+
pub repost: bool,
2323
}
2424

25-
impl Summary for Tweet {
25+
impl Summary for SocialPost {
2626
fn summarize(&self) -> String {
2727
format!("{}: {}", self.username, self.content)
2828
}

listings/ch10-generic-types-traits-and-lifetimes/no-listing-05-returning-impl-trait/src/lib.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,28 +15,28 @@ impl Summary for NewsArticle {
1515
}
1616
}
1717

18-
pub struct Tweet {
18+
pub struct SocialPost {
1919
pub username: String,
2020
pub content: String,
2121
pub reply: bool,
22-
pub retweet: bool,
22+
pub repost: bool,
2323
}
2424

25-
impl Summary for Tweet {
25+
impl Summary for SocialPost {
2626
fn summarize(&self) -> String {
2727
format!("{}: {}", self.username, self.content)
2828
}
2929
}
3030

3131
// ANCHOR: here
3232
fn returns_summarizable() -> impl Summary {
33-
Tweet {
33+
SocialPost {
3434
username: String::from("horse_ebooks"),
3535
content: String::from(
3636
"of course, as you probably already know, people",
3737
),
3838
reply: false,
39-
retweet: false,
39+
repost: false,
4040
}
4141
}
4242
// ANCHOR_END: here

0 commit comments

Comments
 (0)