Since .max()
doesn't work for f64
s, I'm writing a ForceOrd
struct that asserts that the argument isn't a NaN
. The intended usage is something like:
let m = xs.iter().map(|&x| ForceOrd(x)).max().unwrap().into();
However, I can't get the Into
trait implementation to compile with the error:
conflicting implementations of trait `std::convert::Into<_>` for type `ForceOrd<_>`
The code (playground):
#[derive(PartialEq, PartialOrd)]
pub struct ForceOrd<X: PartialEq + PartialOrd>(pub X);
impl<X: PartialEq + PartialOrd> Eq for ForceOrd<X> { }
impl<X: PartialEq + PartialOrd> Ord for ForceOrd<X> {
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
self.0.partial_cmp(&other.0).unwrap()
}
}
/// doesn't work
impl<X: PartialEq + PartialOrd> Into<X> for ForceOrd<X> {
fn into(x: Self) -> X { x.0 }
}
/// doesn't work either
impl<X: PartialEq + PartialOrd> From<ForceOrd<X>> for X {
fn from(x: ForceOrd<X>) -> Self { x.0 }
}