Construction

Trait Construction 

Source
pub trait Construction<T>:
    Semigroup
    + Sized
    + From<T>
    + Deref<Target = T>
    + DerefMut {
    // Required method
    fn into_inner(self) -> T;

    // Provided method
    fn lift_op(base: T, other: T) -> T { ... }
}
Expand description

Construction represents crate::Semigroup as a new type struct.

§Example

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

Required Methods§

Source

fn into_inner(self) -> T

Convert into inner type of new type struct.

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

#[derive(Construction)]
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 = Coalesce(Some(1));
assert_eq!(a.into_inner(), Some(1));

Provided Methods§

Source

fn lift_op(base: T, other: T) -> T

Semigroup operation between base and other with constructed type. When T does not implement crate::Semigroup, this function can be used.

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

#[derive(Construction)]
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 = None;
let b = Some(2);
assert_eq!(Coalesce::lift_op(a, b), Some(2));

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> Construction<Option<T>> for Coalesce<T>

Source§

impl<T> Construction<T> for Overwrite<T>

Source§

impl<T: Ord> Construction<T> for Max<T>

Source§

impl<T: Ord> Construction<T> for Min<T>

Source§

impl<T: IntoIterator + FromIterator<T::Item>> Construction<T> for Concat<T>

Source§

impl<T: Add<Output = T>> Construction<T> for Sum<T>

Source§

impl<T: Mul<Output = T>> Construction<T> for Prod<T>

Source§

impl<T: BitXor<Output = T>> Construction<T> for Xor<T>

Source§

impl<T: Counter> Construction<Histogram<T>> for HdrHistogram<T>

Available on crate feature histogram only.
Source§

impl<T: Unsigned + Integer + Clone> Construction<T> for Gcd<T>

Available on crate feature monoid only.
Source§

impl<T: Unsigned + Integer + Clone> Construction<T> for Lcm<T>

Available on crate feature monoid only.
Source§

impl<T: Semigroup> Construction<Option<T>> for OptionMonoid<T>

Available on crate feature monoid only.