pub trait Near<Rhs: ?Sized = Self, Tolerance = f32> {
// Required method
fn near(&self, other: &Rhs, tolerance: &Tolerance) -> bool;
}Expand description
Trait for if something is “near” within a specified tolerance.
§Examples
Basic use:
pub struct MyFloat(f32);
impl Near for MyFloat {
fn near(&self, other: &MyFloat, tolerance: &f32) -> bool {
self.0.near(&other.0, tolerance)
}
}
assert!(&MyFloat(0.0001).near(&MyFloat(0.00011), &0.0001));
assert!(!&MyFloat(0.0001).near(&MyFloat(0.0011), &0.000001));