use errlanes::UnmappedInto;
use crate::{Fail, Fatal, Fault, Lift, Rejection, RepoFault, RepoWriteError};
pub trait WriteShape {
type Error<CV: Rejection>;
type Or<S: WriteShape>: WriteShape;
}
#[doc(hidden)]
pub trait WriteShapes {
type Create: WriteShape;
type Update: WriteShape;
}
pub struct Rejects;
pub struct Faults;
impl WriteShape for Rejects {
type Error<CV: Rejection> = RepoWriteError<CV>;
type Or<S: WriteShape> = Rejects;
}
impl WriteShape for Faults {
type Error<CV: Rejection> = RepoFault;
type Or<S: WriteShape> = S;
}
pub trait LiftNestedWrite<ParentCv>: Sized {
type Out;
fn lift_nested(self) -> Self::Out;
}
impl<ChildCv, ParentCv> LiftNestedWrite<ParentCv> for RepoWriteError<ChildCv>
where
ChildCv: Rejection,
ParentCv: Rejection + Lift<ChildCv>,
<ParentCv as Lift<ChildCv>>::Unmapped: UnmappedInto<Fatal>,
{
type Out = RepoWriteError<ParentCv>;
fn lift_nested(self) -> RepoWriteError<ParentCv> {
Fail::lift::<ParentCv, errlanes::lanes!(Transient, Fatal)>(self)
}
}
impl<ParentCv> LiftNestedWrite<ParentCv> for RepoFault {
type Out = RepoFault;
fn lift_nested(self) -> RepoFault {
let fault: Fault<errlanes::lanes!(Transient, Fatal)> = self;
fault
}
}