Trait CloseTo

Source
pub trait CloseTo {
    type Item;

    // Required methods
    fn close_to(&self, x: &Self::Item, y: &Self::Item) -> bool;
    fn close_to_zero(&self, x: &Self::Item) -> bool;

    // Provided method
    fn close_to_iter<'a, Iter1, Iter2>(&'a self, x: Iter1, y: Iter2) -> bool
       where Iter1: Iterator<Item = &'a Self::Item>,
             Iter2: Iterator<Item = &'a Self::Item> { ... }
}
Expand description

A possibly-stateful comparison for exact or approximate types.

Implementors of this trait can be used to compare Items for “closeness”. The idea is that closeness should encompass absolute equality as well as approximate equality.

For exact types, use the CloseToEq struct to just fall back to direct comparison. For inexact types, use the RelativeParams struct to specify the acceptable (relative) error.

Required Associated Types§

Source

type Item

The type of thing that can be compared.

Required Methods§

Source

fn close_to(&self, x: &Self::Item, y: &Self::Item) -> bool

Returns true iff x is approximatey equal to y.

Source

fn close_to_zero(&self, x: &Self::Item) -> bool

Indicates true if x is approximately zero.

Provided Methods§

Source

fn close_to_iter<'a, Iter1, Iter2>(&'a self, x: Iter1, y: Iter2) -> bool
where Iter1: Iterator<Item = &'a Self::Item>, Iter2: Iterator<Item = &'a Self::Item>,

Checks closeness over an iteration.

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.

Implementors§