alloy::cmp

Trait Near

source
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));

Required Methods§

source

fn near(&self, other: &Rhs, tolerance: &Tolerance) -> bool

Tests whether self is “near” other relative top the specified tolerance

§Parameters
  • other - the other value to test against
  • tolerance - the tolerance being tested

Implementations on Foreign Types§

source§

impl Near for f32

source§

fn near(&self, other: &Self, distance: &f32) -> bool

source§

impl Near for f64

source§

fn near(&self, other: &Self, distance: &f32) -> bool

source§

impl Near<f32, f64> for f32

source§

fn near(&self, other: &Self, distance: &f64) -> bool

source§

impl Near<f64, f64> for f64

source§

fn near(&self, other: &Self, distance: &f64) -> bool

source§

impl Near<Degree> for f32

source§

fn near(&self, other: &Degree, tolerance: &f32) -> bool

source§

impl Near<Gradian> for f32

source§

fn near(&self, other: &Gradian, tolerance: &f32) -> bool

source§

impl Near<Radian> for f32

source§

fn near(&self, other: &Radian, tolerance: &f32) -> bool

source§

impl Near<Unit> for f32

source§

fn near(&self, other: &Unit, tolerance: &f32) -> bool

source§

impl<T, U> Near<[T], U> for [T]
where T: Near<T, U>,

source§

fn near(&self, other: &Self, tolerance: &U) -> bool

source§

impl<const N: usize, T, U> Near<[T; N], U> for [T; N]
where T: Near<T, U>,

source§

fn near(&self, other: &Self, tolerance: &U) -> bool

Implementors§