Skip to main content

AddMonoid

Trait AddMonoid 

Source
pub trait AddMonoid:
    Add<Output = Self>
    + AddAssign
    + Zero
    + Clone { }
Expand description

Represents an Additive Monoid.

A monoid is an algebraic structure with a single associative binary operation and an identity element. An additive monoid is one where the operation is addition (+).

§Mathematical Definition

A set S with a binary operation + is an additive monoid if it satisfies:

  1. Closure: a + b is in S. (Implicit in Rust).
  2. Associativity: (a + b) + c = a + (b + c) for all a, b, c in S. (A property the implementor must uphold).
  3. Identity Element: There exists an element 0 in S such that a + 0 = 0 + a = a for all a in S. (Provided by the Zero trait).

The Clone and AddAssign bounds are included for practical purposes.

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§

Source§

impl<T> AddMonoid for T
where T: Add<Output = Self> + AddAssign + Zero + Clone,