diff --git a/.idea/misc.xml b/.idea/misc.xml
index baf7791..92170b1 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -16,6 +16,8 @@
+
+
diff --git a/.idea/rust.iml b/.idea/rust.iml
index a8e328f..454cb85 100644
--- a/.idea/rust.iml
+++ b/.idea/rust.iml
@@ -63,12 +63,20 @@
+
+
+
+
+
+
+
+
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 145a8ab..5bf83ff 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -2,7 +2,6 @@
-
@@ -16,23 +15,42 @@
-
+
-
-
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
+
+
-
+
-
-
+
+
+
+
+
+
+
+
+
+
@@ -79,6 +97,13 @@
+
+
+
+
+
+
+
@@ -88,11 +113,11 @@
false
false
-
-
-
-
-
+
+
+
+
+
@@ -112,7 +137,13 @@
-
+
+
+
+
+
+
+
@@ -145,7 +176,7 @@
-
+
@@ -173,7 +204,7 @@
-
+
@@ -212,6 +243,26 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -222,26 +273,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -251,20 +282,20 @@
+
+
-
-
-
+
-
-
+
+
@@ -272,7 +303,7 @@
-
+
@@ -280,7 +311,7 @@
-
+
@@ -454,6 +485,13 @@
+
+
+
+
+
+
+
@@ -465,10 +503,45 @@
-
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/generics/Cargo.toml b/generics/Cargo.toml
new file mode 100644
index 0000000..e4c1276
--- /dev/null
+++ b/generics/Cargo.toml
@@ -0,0 +1,7 @@
+[package]
+name = "generics"
+version = "0.1.0"
+authors = ["Timothy Warren "]
+edition = "2018"
+
+[dependencies]
diff --git a/generics/src/lib.rs b/generics/src/lib.rs
new file mode 100644
index 0000000..d39b186
--- /dev/null
+++ b/generics/src/lib.rs
@@ -0,0 +1,80 @@
+use std::fmt::Display;
+
+struct Pair {
+ x: T,
+ y: T,
+}
+
+impl Pair {
+ fn new(x: T, y: T) -> Self {
+ Self {
+ x,
+ y,
+ }
+ }
+}
+
+// Only implements method if both traits are satisfied
+impl Pair {
+ fn cmp_display(&self) {
+ if self.x >= self.y {
+ println!("The largest member is x = {}", self.x);
+ } else {
+ println!("The largest member is y = {}", self.y);
+ }
+ }
+}
+
+pub trait Summary {
+ fn summarize_author(&self) -> String;
+
+ // default implementation
+ fn summarize(&self) -> String {
+ String::from("(Read more...)")
+ }
+}
+
+pub struct NewsArticle {
+ pub headline: String,
+ pub location: String,
+ pub author: String,
+ pub content: String,
+}
+
+impl Summary for NewsArticle {
+ fn summarize_author(&self) -> String {
+ self.author.to_string()
+ }
+
+ fn summarize(&self) -> String {
+ format!("{}, by {} ({})", self.headline, self.author, self.location)
+ }
+}
+
+pub struct Tweet {
+ pub username: String,
+ pub content: String,
+ pub reply: bool,
+ pub retweet: bool,
+}
+
+// Uses default implementation for summarize method
+impl Summary for Tweet {
+ fn summarize_author(&self) -> String {
+ format!("@{}", self.username)
+ }
+}
+
+pub fn returns_summarizable() -> impl Summary {
+ Tweet {
+ username: String::from("horse_ebooks"),
+ content: String::from("of course, as you probably already know, people"),
+ reply: false,
+ retweet: false,
+ }
+}
+
+// Function/method requiring a trait's implementation
+// pub fn notify(item: impl Summary) {
+// println!("Breaking news! {}", item.summarize());
+// }
diff --git a/generics/src/main.rs b/generics/src/main.rs
new file mode 100644
index 0000000..2816884
--- /dev/null
+++ b/generics/src/main.rs
@@ -0,0 +1,40 @@
+mod lib;
+mod point;
+
+use point::{Point, DoubleGenericPoint};
+
+// Works on types implementing both the PartialOrd and Copy traits
+fn largest(list: &[T]) -> T {
+ let mut largest = list[0];
+
+ for &item in list.iter() {
+ if item > largest {
+ largest = item;
+ }
+ }
+
+ largest
+}
+
+fn main() {
+ let number_list = vec![34, 50, 25, 100, 65];
+
+ let result = largest(&number_list);
+ println!("The largest number is {}", result);
+
+ let char_list = vec!['y', 'm', 'a', 'q'];
+
+ let result = largest(&char_list);
+ println!("The largest char is {}", result);
+
+ let p = Point { x: 5, y: 10 };
+
+ println!("p.x = {}", p.x());
+
+ let p1 = DoubleGenericPoint { x: 5, y: 10.4 };
+ let p2 = DoubleGenericPoint { x: "Hello", y: 'c'};
+
+ let p3 = p1.mixup(p2);
+
+ println!("p3.x = {}, p3.y = {}", p3.x, p3.y);
+}
diff --git a/generics/src/point.rs b/generics/src/point.rs
new file mode 100644
index 0000000..5174a97
--- /dev/null
+++ b/generics/src/point.rs
@@ -0,0 +1,34 @@
+// Double generic types for a struct
+pub struct DoubleGenericPoint {
+ pub x: T,
+ pub y: U,
+}
+
+impl DoubleGenericPoint {
+ // Takes a generic of potentially different types than the parent struct
+ pub fn mixup(self, other: DoubleGenericPoint) -> DoubleGenericPoint {
+ DoubleGenericPoint {
+ x: self.x,
+ y: other.y
+ }
+ }
+}
+
+pub struct Point {
+ pub x: T,
+ pub y: T,
+}
+
+// Implement generic methods on a generic struct
+impl Point {
+ pub fn x(&self) -> &T {
+ &self.x
+ }
+}
+
+// Implement a method for only a specific type of generic
+impl Point {
+ fn distance_from_origin(&self) -> f32 {
+ (self.x.powi(2) + self.y.powi(2)).sqrt()
+ }
+}