Hi, I try to rewrite this Rosetta Code example
I want to make it more generic and (hopefully) more idiomatic. But I struggle with a generic function
#[derive(Debug, Clone)]
struct Point<T> {
x: T,
y: T,
}
impl<T> Point<T> {
fn new(x1: T, y1: T) -> Point<T> {
Point { x: x1, y: y1 }
}
}
fn lowest_point(points: &Vec<Point<T>>) -> Result {
points
.iter()
.enumerate()
.min_by(|lhs, rhs| lhs.1.y.partial_cmp(&rhs.1.y).unwrap())
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_one() {
let points = vec![
Point::new(16., 3.),
Point::new(12., 17.),
Point::new(0., 6.),
Point::new(-4., -6.),
Point::new(16., 6.),
Point::new(16., -7.),
Point::new(16., -3.),
Point::new(17., -4.),
Point::new(5., 19.),
Point::new(19., -8.),
Point::new(3., 16.),
Point::new(12., 13.),
Point::new(3., -4.),
Point::new(17., 5.),
Point::new(-3., 15.),
Point::new(-3., -9.),
Point::new(0., 11.),
Point::new(-9., -3.),
Point::new(-4., -2.),
Point::new(12., 10.),
];
println!("{:?}", points);
// let lowest = lowest_point(points);
// println!("{:?}", lowest);
// assert!(lowest)
}
}
I have problems with the function "lowest_point". I don't know how the function signature should look like.