我想用float_cmp::approx_eq
(例如)完成所有浮点比较,但继续使用相等比较运算符==
。我如何实现这一目标?
impl PartialEq for f32 {
fn eq(&self, other: &Self) -> bool {
approx_eq!(f32, *self, *other)
}
}
结果是:
error[E0119]: conflicting implementations of trait `std::cmp::PartialEq` for type `f32`
error[E0117]: only traits defined in the current crate can be implemented for arbitrary types