compris 0.0.11

Composite Primitive Schema (CPS) for Rust
Documentation
use super::super::traits::*;

use {kutil::std::error::*, std::marker::*};

/// An [ErrorReceiver] wrapper that calls [IntoAnnotated::into_annotated] on all errors.
#[derive(Debug)]
pub struct IntoAnnotatedErrorReceiver<'own, InnerT, ErrorT> {
    /// Inner.
    pub inner: &'own mut InnerT,

    error: PhantomData<ErrorT>,
}

impl<'own, InnerT, ErrorT, NewErrorT> ErrorReceiver<NewErrorT> for IntoAnnotatedErrorReceiver<'own, InnerT, ErrorT>
where
    InnerT: ErrorReceiver<ErrorT>,
    ErrorT: IntoAnnotated<NewErrorT>,
    NewErrorT: IntoAnnotated<ErrorT>,
{
    fn give_error(&mut self, error: NewErrorT) -> Result<(), NewErrorT> {
        self.inner.give_error(error.into_annotated()).map_err(|error| error.into_annotated())
    }
}

impl<'own, InnerT, ErrorT> IntoAnnotated<IntoAnnotatedErrorReceiver<'own, InnerT, ErrorT>> for &'own mut InnerT {
    fn into_annotated(self) -> IntoAnnotatedErrorReceiver<'own, InnerT, ErrorT> {
        IntoAnnotatedErrorReceiver { inner: self, error: PhantomData }
    }
}