diff options
author | Adam Carpenter <gitlab@53hor.net> | 2019-07-09 15:14:04 -0400 |
---|---|---|
committer | Adam Carpenter <gitlab@53hor.net> | 2019-07-09 15:14:04 -0400 |
commit | 7e8ee5ed9cad6484e9f13f81731b102ced58402e (patch) | |
tree | 5395402ab07bbb5a659dbd68c701e22a1227202f /rust-book/generics | |
download | learning-rust-7e8ee5ed9cad6484e9f13f81731b102ced58402e.tar.xz learning-rust-7e8ee5ed9cad6484e9f13f81731b102ced58402e.zip |
Init.
Diffstat (limited to 'rust-book/generics')
-rwxr-xr-x | rust-book/generics/Cargo.lock | 4 | ||||
-rwxr-xr-x | rust-book/generics/Cargo.toml | 7 | ||||
-rwxr-xr-x | rust-book/generics/src/main.rs | 68 |
3 files changed, 79 insertions, 0 deletions
diff --git a/rust-book/generics/Cargo.lock b/rust-book/generics/Cargo.lock new file mode 100755 index 0000000..3ddbc8c --- /dev/null +++ b/rust-book/generics/Cargo.lock @@ -0,0 +1,4 @@ +[[package]] +name = "generics" +version = "0.1.0" + diff --git a/rust-book/generics/Cargo.toml b/rust-book/generics/Cargo.toml new file mode 100755 index 0000000..5529f73 --- /dev/null +++ b/rust-book/generics/Cargo.toml @@ -0,0 +1,7 @@ +[package] +name = "generics" +version = "0.1.0" +authors = ["Adam Carpenter <adam.carpenter@adp.com>"] +edition = "2018" + +[dependencies] diff --git a/rust-book/generics/src/main.rs b/rust-book/generics/src/main.rs new file mode 100755 index 0000000..e41d6f5 --- /dev/null +++ b/rust-book/generics/src/main.rs @@ -0,0 +1,68 @@ +//struct Point<T, U> { +// x: T, +// y: U, +//} + +//impl<T, U> Point<T, U> { +// fn x(&self) -> &T { +// &self.x +// } +// +// fn y(&self) -> &T { +// &self.y +// } + +// fn mixup<V, W>(self, other: Point<V, W>) -> Point<T, W> { +// Point { +// x: self.x, +// y: other.y, +// } +// } +//} + +fn largest<T: PartialOrd + Copy>(list: &[T]) -> T { + let mut largest = list[0]; + + for &item in list.iter() { + + if item > largest { + largest = item; + } + + } + + largest +} + +//enum Option_i32 { +// Some(i32), +// None, +//} +// +//enum Option_f64 { +// Some(f64), +// None, +//} + +fn main() { + let number_list = vec![34, 50, 25, 100, 65]; + dbg!(largest(&number_list)); + let char_list = vec!['h', 'e', 'l', 'l', 'o']; + dbg!(largest(&char_list)); +// let integer = Point { x: 5, y: 10 }; +// let float = Point { x: 5.0, y: 10.0 }; + +// let p = Point { x: 5.0, y: 10.5 }; +// dbg!(p.x()); +// dbg!(p.y()); + +// let p1 = Point { x: 5, y: 10.4 }; +// let p2 = Point { x: "Hello", y: 'c' }; +// let p3 = p1.mixup(p2); +// +// dbg!(p3.x); +// dbg!(p3.y); + +// let integer = Option_i32::Some(5); +// let float = Option_f64::Some(5.0); +} |