ConstructionAnnotated

Trait ConstructionAnnotated 

Source
pub trait ConstructionAnnotated<T, A>:
    Construction<T>
    + AnnotatedSemigroup<A>
    + Annotate<A> {
    // Provided method
    fn lift_annotated_op(
        base: Annotated<T, A>,
        other: Annotated<T, A>,
    ) -> Annotated<T, A> { ... }
}
Expand description

ConstructionAnnotated represents crate::AnnotatedSemigroup as a new type struct like Construction.

§Example

TODO more derive details

Provided Methods§

Source

fn lift_annotated_op( base: Annotated<T, A>, other: Annotated<T, A>, ) -> Annotated<T, A>

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

§Example
use semigroup::{AnnotatedSemigroup, Annotated, Construction, ConstructionAnnotated, Semigroup};

#[derive(Construction)]
#[construction(annotated)]
struct Coalesce<T>(Option<T>);
impl<A, T> AnnotatedSemigroup<A> for Coalesce<T> {
    fn annotated_op(base: Annotated<Self, A>, other: Annotated<Self, A>) -> Annotated<Self, A> {
        match (&base.value().0, &other.value().0) {
            (Some(_), _) | (None, None) => base,
            (None, Some(_)) => other,
        }
    }
}

let a = Annotated::new(None, "first");
let b = Annotated::new(Some(2), "second");
assert_eq!(Coalesce::lift_annotated_op(a, b), b);

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§