From ef1bf4921ee4127d461eec03a14c9070d193345c Mon Sep 17 00:00:00 2001 From: Adam Carpenter Date: Mon, 11 Feb 2019 16:59:01 -0500 Subject: Init. --- generics/src/main.rs | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 generics/src/main.rs (limited to 'generics/src') diff --git a/generics/src/main.rs b/generics/src/main.rs new file mode 100644 index 0000000..e41d6f5 --- /dev/null +++ b/generics/src/main.rs @@ -0,0 +1,68 @@ +//struct Point { +// x: T, +// y: U, +//} + +//impl Point { +// fn x(&self) -> &T { +// &self.x +// } +// +// fn y(&self) -> &T { +// &self.y +// } + +// fn mixup(self, other: Point) -> Point { +// Point { +// x: self.x, +// y: other.y, +// } +// } +//} + +fn largest(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); +} -- cgit v1.2.3