Skip to main content

ExactArith

Trait ExactArith 

Source
pub trait ExactArith: Cost {
    type Exact: ExactNumber;

    // Required method
    fn exact(self) -> Self::Exact;
}
Expand description

A cost that converts into an ExactNumber without loss.

An additive companion of Cost and WideMul: cost types without it keep working everywhere else.

CostExact
u8 to u128, usizeBigUint
Decimal<K>BigUint of the raw value (scale 10^K)
NonNegF64 (feature float)NonNegF64

§Examples

use search_core::ExactArith;

// (d1 · c1 + s) · c2 against (d2 · c2 + s) · c1 without overflow.
let e = |x: u64| x.exact();
let left = (e(u64::MAX) * e(u64::MAX) + e(7)) * e(u64::MAX);
let right = (e(1) * e(u64::MAX) + e(7)) * e(u64::MAX);
assert!(left > right);

Required Associated Types§

Source

type Exact: ExactNumber

The exact number type.

Required Methods§

Source

fn exact(self) -> Self::Exact

The cost as an exact number.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl ExactArith for u8

Source§

impl ExactArith for u16

Source§

impl ExactArith for u32

Source§

impl ExactArith for u64

Source§

impl ExactArith for u128

Source§

impl ExactArith for usize

Implementors§

Source§

impl ExactArith for NonNegF64

Available on crate feature float only.
Source§

impl<const K: u32> ExactArith for Decimal<K>