summaryrefslogtreecommitdiff
path: root/rust-book/generics/src/main.rs
blob: e41d6f5b1102e2cde00db75303f6746bbcd0b2d4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
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);
}