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§
Sourcefn into_inner(self) -> T
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§
Sourcefn lift_op(base: T, other: T) -> T
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§
impl<T> Construction<Option<T>> for Coalesce<T>
impl<T> Construction<T> for Overwrite<T>
impl<T: Ord> Construction<T> for Max<T>
impl<T: Ord> Construction<T> for Min<T>
impl<T: IntoIterator + FromIterator<T::Item>> Construction<T> for Concat<T>
impl<T: Add<Output = T>> Construction<T> for Sum<T>
impl<T: Mul<Output = T>> Construction<T> for Prod<T>
impl<T: BitXor<Output = T>> Construction<T> for Xor<T>
impl<T: Counter> Construction<Histogram<T>> for HdrHistogram<T>
Available on crate feature
histogram only.impl<T: Unsigned + Integer + Clone> Construction<T> for Gcd<T>
Available on crate feature
monoid only.impl<T: Unsigned + Integer + Clone> Construction<T> for Lcm<T>
Available on crate feature
monoid only.impl<T: Semigroup> Construction<Option<T>> for OptionMonoid<T>
Available on crate feature
monoid only.