use crate::{
add_generics::WithGenerics, assertable::Assertable, generatable::Generatable,
maybe_borrowed::MaybeBorrowed, raw_assert::r#trait::RawAssertable, raw_assert::RawAssert,
};
pub struct Assert<'a, T>
where
T: Generatable<'a>,
{
pub template: MaybeBorrowed<'a, T>,
pub assert: MaybeBorrowed<'a, T::Assert>,
}
pub trait InsertIntoTemplate<'a, T>
where
T: Generatable<'a> + 'a,
{
type Output: RawAssertable<'a>;
fn test<U>(self, ty: U) -> Self::Output
where
U: Into<MaybeBorrowed<'a, T::Assert>>;
}
impl<'a, T> InsertIntoTemplate<'a, T> for T
where
T: Generatable<'a> + 'a + Ord + Eq,
T::Assert: Ord + Eq,
{
type Output = Assert<'a, T>;
fn test<U>(self, ty: U) -> Assert<'a, T>
where
U: Into<MaybeBorrowed<'a, T::Assert>>,
{
Assert {
template: MaybeBorrowed::Owned(self),
assert: ty.into(),
}
}
}
impl<'a, T> InsertIntoTemplate<'a, T> for &'a T
where
T: Generatable<'a> + 'a + Ord + Eq,
T::Assert: Ord + Eq,
{
type Output = Assert<'a, T>;
fn test<U>(self, ty: U) -> Assert<'a, T>
where
U: Into<MaybeBorrowed<'a, T::Assert>>,
{
Assert {
template: MaybeBorrowed::Borrowed(self),
assert: ty.into(),
}
}
}
impl<'a, T> InsertIntoTemplate<'a, T> for WithGenerics<'a, T>
where
T: Generatable<'a> + Eq + Ord,
T::Assert: Eq + Ord,
{
type Output = RawAssert<'a, T>;
fn test<U>(self, ty: U) -> RawAssert<'a, T>
where
U: Into<MaybeBorrowed<'a, T::Assert>>,
{
RawAssert {
template: self.data.into(),
generics: self.generics,
assert: ty.into(),
}
}
}
impl<'a, T> InsertIntoTemplate<'a, T> for WithGenerics<'a, MaybeBorrowed<'a, T>>
where
T: Generatable<'a> + Eq + Ord,
T::Assert: Eq + Ord,
{
type Output = WithGenerics<'a, Assert<'a, T>>;
fn test<U>(self, ty: U) -> Self::Output
where
U: Into<MaybeBorrowed<'a, T::Assert>>,
{
WithGenerics {
data: Assert {
template: self.data,
assert: ty.into(),
},
generics: self.generics,
}
}
}
impl<'a, T> Assertable<'a> for Assert<'a, T>
where
T: Generatable<'a> + Eq + Ord,
T::Assert: Eq + Ord,
{
type Output = RawAssert<'a, T>;
fn do_assert(self) -> Self::Output {
RawAssert {
template: self.template,
generics: None,
assert: self.assert,
}
}
}