From 67cdcc2e12118becb823e20a40cc2687f2b8425a Mon Sep 17 00:00:00 2001 From: Adam Carpenter <53hornet@gmail.com> Date: Wed, 27 Mar 2019 15:32:37 -0400 Subject: Started Rust in Action MEAP. --- traits/src/main.rs | 114 ----------------------------------------------------- 1 file changed, 114 deletions(-) delete mode 100644 traits/src/main.rs (limited to 'traits/src') diff --git a/traits/src/main.rs b/traits/src/main.rs deleted file mode 100644 index 770caa9..0000000 --- a/traits/src/main.rs +++ /dev/null @@ -1,114 +0,0 @@ -use std::fmt::Display; - -struct Pair { - x: T, - y: T, -} - -impl Pair { - fn new(x: T, y: T) -> Self { - Self { - x, - y, - } - } -} - -impl Pair { - fn cmp_display(&self) { - if self.x >= self.y { - println!("{}", self.x); - } - else { - println!("{}", self.y); - } - } -} - -pub trait Summary { - fn summarize(&self) -> String { - format!("(read more from {}...)", self.summarize_author()) - } - - fn summarize_author(&self) -> String; -} - -pub struct NewsArticle { - pub headline: String, - pub location: String, - pub author: String, - pub content: String, -} - -impl Summary for NewsArticle { -// fn summarize(&self) -> String { -// format!("{}, by {} ({})", self.headline, self.author, self.location) -// } - - fn summarize_author(&self) -> String { - format!("{}", self.author) - } - -} - -pub struct Tweet { - pub username: String, - pub content: String, - pub reply: bool, - pub retweet: bool, -} - -impl Summary for Tweet { -// fn summarize(&self) -> String { -// format!("{}: {}", self.username, self.content) -// } - - fn summarize_author(&self) -> String { - format!("@{}", self.username) - } -} - -pub fn notify(item: impl Summary) { - println!("breaking news: {}", item.summarize()); -} - -fn returns_summarizable() -> impl Summary { - - NewsArticle { - headline: String::from("Penguins win the stanley cup championship!"), - location: String::from("Pittsburgh, PA, USA"), - author: String::from("Iceburgh"), - content: String::from("The pittsburgh penguins are winners I guess."), - } -// Tweet { -// username: String::from("horse_ebooks"), -// content: String::from("of course blargh"), -// reply: false, -// retweet: false, -// } -} - -fn main() { - - let tweet = Tweet { - username: String::from("horse_ebooks"), - content: String::from("of course, as you probably already know, people"), - reply: false, - retweet: false, - }; - - //dbg!(tweet.summarize()); - - let article = NewsArticle { - headline: String::from("Penguins win the stanley cup championship!"), - location: String::from("Pittsburgh, PA, USA"), - author: String::from("Iceburgh"), - content: String::from("The pittsburgh penguins are winners I guess."), - }; - - //dbg!(article.summarize()); - - //notify(tweet); - - returns_summarizable(); -} -- cgit v1.2.3