libpuri

Trait Monoid

Source
pub trait Monoid {
    const ID: Self;

    // Required method
    fn op(&self, rhs: &Self) -> Self;
}
Expand description

Trait for associative binary operations with an identity element.

Monoid requires that the following property holds:

// The operation * is associative.
(a * b) * c == a * (b * c)

// There exists an identity element.
a * id == id * a == a

This property cannot be checked by the compiler so the implementer should verify it by themself.

Required Associated Constants§

Source

const ID: Self

The identity element.

Required Methods§

Source

fn op(&self, rhs: &Self) -> Self

An associative binary operator on monoid elements.

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§