Skip to main content

Loss

Trait Loss 

Source
pub trait Loss: Clone + Default {
    // Required methods
    fn zero() -> Self;
    fn total() -> Self;
    fn is_zero(&self) -> bool;
    fn combine(self, other: Self) -> Self;
}
Expand description

A measure of what didn’t survive a transformation.

Loss forms a monoid: zero() is the identity element, combine is associative, and total() is the absorbing element (annihilator).

Required Methods§

Source

fn zero() -> Self

The identity: no loss occurred. combine(zero(), x) == x.

Source

fn total() -> Self

Total loss: the transformation destroyed everything. Acts as an absorbing element under combine.

Source

fn is_zero(&self) -> bool

Whether this loss is zero (lossless).

Source

fn combine(self, other: Self) -> Self

Accumulate two losses. Associative: a.combine(b).combine(c) == a.combine(b.combine(c)).

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 Loss for String

Source§

fn zero() -> Self

Source§

fn total() -> Self

Source§

fn is_zero(&self) -> bool

Source§

fn combine(self, other: Self) -> Self

Source§

impl Loss for f64

Source§

fn zero() -> Self

Source§

fn total() -> Self

Source§

fn is_zero(&self) -> bool

Source§

fn combine(self, other: Self) -> Self

Source§

impl Loss for u64

Source§

fn zero() -> Self

Source§

fn total() -> Self

Source§

fn is_zero(&self) -> bool

Source§

fn combine(self, other: Self) -> Self

Source§

impl Loss for usize

Source§

fn zero() -> Self

Source§

fn total() -> Self

Source§

fn is_zero(&self) -> bool

Source§

fn combine(self, other: Self) -> Self

Source§

impl<A: Loss, B: Loss> Loss for (A, B)

Source§

fn zero() -> Self

Source§

fn total() -> Self

Source§

fn is_zero(&self) -> bool

Source§

fn combine(self, other: Self) -> Self

Source§

impl<T: Clone> Loss for Vec<T>

Source§

fn zero() -> Self

Source§

fn total() -> Self

Source§

fn is_zero(&self) -> bool

Source§

fn combine(self, other: Self) -> Self

Source§

impl<T: Eq + Hash + Clone> Loss for HashSet<T>

Source§

fn zero() -> Self

Source§

fn total() -> Self

Source§

fn is_zero(&self) -> bool

Source§

fn combine(self, other: Self) -> Self

Source§

impl<T: Ord + Clone> Loss for BTreeSet<T>

Source§

fn zero() -> Self

Source§

fn total() -> Self

Source§

fn is_zero(&self) -> bool

Source§

fn combine(self, other: Self) -> Self

Implementors§