ConstructionMonoid

Trait ConstructionMonoid 

Source
pub trait ConstructionMonoid<T>: Construction<T> + Monoid {
    // Provided method
    fn lift_unit() -> T { ... }
}
Available on crate feature monoid only.
Expand description

ConstructionMonoid represents crate::Monoid as a new type struct. like Construction.

§Example

Simple example see crate::Monoid. TODO more derive details

Provided Methods§

Source

fn lift_unit() -> T

Get monoid identity element with constructed type. When T does not implement crate::Monoid, this function can be used.

§Example
use semigroup::{Construction, ConstructionMonoid, Semigroup};

#[derive(Construction)]
#[construction(monoid, unit = Self(None))]
struct Coalesce<T>(Option<T>);
impl<T> Semigroup for Coalesce<T> {
    fn op(base: Self, other: Self) -> Self {
        Self(base.0.or(other.0))
    }
}

let a: Option<u32> = Coalesce::lift_unit();
assert_eq!(a, None);

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> ConstructionMonoid<Option<T>> for Coalesce<T>
where Self: Monoid,

Source§

impl<T: Ord> ConstructionMonoid<T> for Max<T>
where Self: Monoid,

Source§

impl<T: Ord> ConstructionMonoid<T> for Min<T>
where Self: Monoid,

Source§

impl<T: IntoIterator + FromIterator<T::Item>> ConstructionMonoid<T> for Concat<T>
where Self: Monoid,

Source§

impl<T: Add<Output = T>> ConstructionMonoid<T> for Sum<T>
where Self: Monoid,

Source§

impl<T: Mul<Output = T>> ConstructionMonoid<T> for Prod<T>
where Self: Monoid,

Source§

impl<T: BitXor<Output = T>> ConstructionMonoid<T> for Xor<T>
where Self: Monoid,

Source§

impl<T: Counter> ConstructionMonoid<Histogram<T>> for HdrHistogram<T>
where Self: Monoid,

Available on crate feature histogram only.
Source§

impl<T: Unsigned + Integer + Clone> ConstructionMonoid<T> for Gcd<T>
where Self: Monoid,

Source§

impl<T: Unsigned + Integer + Clone> ConstructionMonoid<T> for Lcm<T>
where Self: Monoid,

Source§

impl<T: Semigroup> ConstructionMonoid<Option<T>> for OptionMonoid<T>
where Self: Monoid,