use std::cmp::PartialOrd;
pub fn largest<T: PartialOrd + Copy>(list: &[T]) -> T {
// The type which impls PartialOrd and Copy trait can use
// the function
let mut largest = list[0]; // Copy trait
for &item in list.iter() {
if item > largest { // PartialOrd trait
largest = item;
}
}
largest
}
#[derive(Debug)]
pub struct Point<T, U> {
pub x: T,
pub y: U,
}
struct Point<T> {
x: T,
y: T,
}
fn main() {
let wont_work = Point { x: 5, y: 4.0 };
}
error[E0308]: mismatched types
--> src/main.rs:7:38
|
7 | let wont_work = Point { x: 5, y: 4.0 };
| ^^^ expected integral variable, found
floating-point variable
|
= note: expected type `{integer}`
found type `{float}`