float_cmp

Trait ApproxEq

Source
pub trait ApproxEq: Sized {
    type Margin: Copy + Default;

    // Required method
    fn approx_eq<M: Into<Self::Margin>>(self, other: Self, margin: M) -> bool;

    // Provided method
    fn approx_ne<M: Into<Self::Margin>>(self, other: Self, margin: M) -> bool { ... }
}
Expand description

A trait for approximate equality comparisons.

Required Associated Types§

Source

type Margin: Copy + Default

This type type defines a margin within which two values are to be considered approximately equal. It must implement Default so that approx_eq() can be called on unknown types.

Required Methods§

Source

fn approx_eq<M: Into<Self::Margin>>(self, other: Self, margin: M) -> bool

This method tests that the self and other values are equal within margin of each other.

Provided Methods§

Source

fn approx_ne<M: Into<Self::Margin>>(self, other: Self, margin: M) -> bool

This method tests that the self and other values are not within margin of each other.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl ApproxEq for f32

Source§

type Margin = F32Margin

Source§

fn approx_eq<M: Into<Self::Margin>>(self, other: f32, margin: M) -> bool

Source§

impl ApproxEq for f64

Source§

type Margin = F64Margin

Source§

fn approx_eq<M: Into<Self::Margin>>(self, other: f64, margin: M) -> bool

Implementors§