Skip to content

Commit 43593d0

Browse files
committed
fmt
1 parent dc29950 commit 43593d0

File tree

5 files changed

+46
-12
lines changed

5 files changed

+46
-12
lines changed

content/lessons/05_types_reasoning/basic_trait_display.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@ struct NewsArticle {
1111

1212
impl Display for NewsArticle {
1313
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
14-
write!(f, "{}, by {} ({})", self.headline, self.author, self.location)
14+
write!(
15+
f,
16+
"{}, by {} ({})",
17+
self.headline, self.author, self.location
18+
)
1519
}
1620
}
1721

@@ -20,7 +24,7 @@ struct Tweet {
2024
content: String,
2125
}
2226

23-
impl Display for Tweet {
27+
impl Display for Tweet {
2428
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
2529
write!(f, "{}: {}", self.username, self.content)
2630
}

content/lessons/05_types_reasoning/impl_trait.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@ struct NewsArticle {
1515

1616
impl Display for NewsArticle {
1717
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
18-
writeln!(f, "{}, by {} ({})", self.headline, self.author, self.location)?;
18+
writeln!(
19+
f,
20+
"{}, by {} ({})",
21+
self.headline, self.author, self.location
22+
)?;
1923
f.write_str(&self.content)
2024
}
2125
}
@@ -25,7 +29,11 @@ struct NewsArticleSummarizer<'a>(&'a NewsArticle);
2529
impl Display for NewsArticleSummarizer<'_> {
2630
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
2731
let article = self.0;
28-
write!(f, "{}, by {} ({})", article.headline, article.author, article.location)
32+
write!(
33+
f,
34+
"{}, by {} ({})",
35+
article.headline, article.author, article.location
36+
)
2937
}
3038
}
3139

content/lessons/05_types_reasoning/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ The use of generic types in `Summary` trait makes it semantics like this:
341341

342342
> Any type can be summarized with any type supporting it.
343343
344-
When we want the trait to require exactly one possible generic implementation for a given type, we can leverage *associated types*. Example here:
344+
When we want the trait to require exactly one possible generic implementation for a given type, we can leverage _associated types_. Example here:
345345

346346
{{ include_code_sample(path="lessons/05_types_reasoning/trait_associated_type.rs", language="rust") }}
347347

content/lessons/05_types_reasoning/trait_associated_type.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@ struct NewsArticle {
1717

1818
impl Display for NewsArticle {
1919
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
20-
writeln!(f, "{}, by {} ({})", self.headline, self.author, self.location)?;
20+
writeln!(
21+
f,
22+
"{}, by {} ({})",
23+
self.headline, self.author, self.location
24+
)?;
2125
f.write_str(&self.content)
2226
}
2327
}
@@ -27,7 +31,11 @@ struct NewsArticleSummarizer<'a>(&'a NewsArticle);
2731
impl Display for NewsArticleSummarizer<'_> {
2832
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
2933
let article = self.0;
30-
write!(f, "{}, by {} ({})", article.headline, article.author, article.location)
34+
write!(
35+
f,
36+
"{}, by {} ({})",
37+
article.headline, article.author, article.location
38+
)
3139
}
3240
}
3341

content/lessons/05_types_reasoning/trait_generic_type.rs

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@ struct NewsArticle {
1515

1616
impl Display for NewsArticle {
1717
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
18-
writeln!(f, "{}, by {} ({})", self.headline, self.author, self.location)?;
18+
writeln!(
19+
f,
20+
"{}, by {} ({})",
21+
self.headline, self.author, self.location
22+
)?;
1923
f.write_str(&self.content)
2024
}
2125
}
@@ -25,7 +29,11 @@ struct NewsArticleSummarizer<'a>(&'a NewsArticle);
2529
impl Display for NewsArticleSummarizer<'_> {
2630
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
2731
let article = self.0;
28-
write!(f, "{}, by {} ({})", article.headline, article.author, article.location)
32+
write!(
33+
f,
34+
"{}, by {} ({})",
35+
article.headline, article.author, article.location
36+
)
2937
}
3038
}
3139

@@ -76,7 +84,13 @@ fn main() {
7684
};
7785

7886
// Compile error: `type annotations needed; multiple `impl`s satisfying `Tweet: Summary<'_, _>` found`
79-
// println!("1 new tweet: {}", tweet.summarize());
80-
println!("1 new tweet: {}", <Tweet as Summary<'_, TweetSummarizer>>::summarize(&tweet));
81-
println!("1 new tweet: {}", <Tweet as Summary<'_, NewsArticleSummarizer>>::summarize(&tweet));
87+
// println!("1 new tweet: {}", tweet.summarize());
88+
println!(
89+
"1 new tweet: {}",
90+
<Tweet as Summary<'_, TweetSummarizer>>::summarize(&tweet)
91+
);
92+
println!(
93+
"1 new tweet: {}",
94+
<Tweet as Summary<'_, NewsArticleSummarizer>>::summarize(&tweet)
95+
);
8296
}

0 commit comments

Comments
 (0)