AoProxy
This commit is contained in:
parent
53266188a3
commit
2e596e4f34
@ -19,9 +19,9 @@ pub trait WithParseMode: ParseMode {
|
||||
type WithMode: ?Sized;
|
||||
}
|
||||
|
||||
pub struct WithMode<F: ?Sized, M: ?Sized>(PhantomData<M>, F);
|
||||
pub struct WithMode<T: ?Sized, M: ?Sized>(PhantomData<M>, T);
|
||||
|
||||
impl<F: ?Sized + ParseMode> WithParseMode for F {
|
||||
impl<T: ?Sized + ParseMode> WithParseMode for T {
|
||||
type WithMode = WithMode<Self, <Self as ParseMode>::Mode>;
|
||||
}
|
||||
|
||||
|
@ -36,11 +36,22 @@ impl<A: AtomicBase> Serializable for AtomicObject<A> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, Ctx: Context<'a>, A: Atomic> Mentionable<'a, Ctx> for AtomicObject<A> {
|
||||
type Fctr = AtomicFactory<A>;
|
||||
pub trait AoProxy<'a, Ctx: Context<'a>>: AtomicProxy {
|
||||
type Mtbl: Mentionable<'a, Ctx, Fctr = Self::Fctr>;
|
||||
type Fctr: Factory<'a, Ctx, Mtbl = Self::Mtbl>;
|
||||
|
||||
fn factory() -> Self::Fctr;
|
||||
fn wrap(a: Self::A) -> Self::Mtbl;
|
||||
}
|
||||
|
||||
impl<'a, Ctx: Context<'a>, A: AtomicBase + WithParseMode> Mentionable<'a, Ctx> for AtomicObject<A>
|
||||
where
|
||||
A::WithMode: AoProxy<'a, Ctx, Mtbl = Self, A = A>,
|
||||
{
|
||||
type Fctr = <A::WithMode as AoProxy<'a, Ctx>>::Fctr;
|
||||
|
||||
fn factory(&self) -> Self::Fctr {
|
||||
AtomicFactory::new()
|
||||
<A::WithMode as AoProxy<'a, Ctx>>::factory()
|
||||
}
|
||||
|
||||
fn topology(&self) -> Hash {
|
||||
@ -67,8 +78,11 @@ impl<A: AtomicBase> Clone for AtomicFactory<A> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, Ctx: Context<'a>, A: Atomic> FactoryBase<'a, Ctx> for AtomicFactory<A> {
|
||||
type Mtbl = AtomicObject<A>;
|
||||
impl<'a, Ctx: Context<'a>, A: AtomicBase + WithParseMode> FactoryBase<'a, Ctx> for AtomicFactory<A>
|
||||
where
|
||||
A::WithMode: AoProxy<'a, Ctx, Fctr = Self, A = A>,
|
||||
{
|
||||
type Mtbl = <A::WithMode as AoProxy<'a, Ctx>>::Mtbl;
|
||||
|
||||
type ParseError = A::AParseError;
|
||||
}
|
||||
@ -77,7 +91,21 @@ impl<A> ParseMode for AtomicFactory<A> {
|
||||
type Mode = RegularMode;
|
||||
}
|
||||
|
||||
impl<'a, Ctx: Context<'a>, A: Atomic> RegularFactory<'a, Ctx> for AtomicFactory<A> {
|
||||
impl<'a, Ctx: Context<'a>, A: RegularAtomic> AoProxy<'a, Ctx> for WithMode<A, RegularMode> {
|
||||
type Mtbl = AtomicObject<A>;
|
||||
|
||||
type Fctr = AtomicFactory<A>;
|
||||
|
||||
fn factory() -> Self::Fctr {
|
||||
AtomicFactory::new()
|
||||
}
|
||||
|
||||
fn wrap(a: Self::A) -> Self::Mtbl {
|
||||
a.into()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, Ctx: Context<'a>, A: RegularAtomic> RegularFactory<'a, Ctx> for AtomicFactory<A> {
|
||||
fn rdeserialize(&self, inctx: impl InCtx<'a, Ctx>) -> ParseResult<'a, Ctx, Self> {
|
||||
Ok(A::a_deserialize(inctx)?.into())
|
||||
}
|
||||
|
@ -48,7 +48,7 @@ pub trait ConstSizeObject<'a, Ctx: Context<'a>>: FixedSizeObject<'a, Ctx> {
|
||||
pub type ADParseResult<A, D> = Result<(A, D), AParseError<A>>;
|
||||
|
||||
/// Atomic analogue of [`InlineableFactory`]/[`InlineableObject`].
|
||||
pub trait InlineableAtomic: AtomicBase {
|
||||
pub trait InlineableAtomic: AtomicBase + ParseMode {
|
||||
fn a_extension_error(tail: &[u8]) -> Self::AParseError;
|
||||
|
||||
fn a_ideserialize<D: Inlining>(inlining: D) -> ADParseResult<Self, D>;
|
||||
@ -63,8 +63,9 @@ pub trait ConstSizeAtomic: InlineableAtomic {
|
||||
const SIZE: usize;
|
||||
}
|
||||
|
||||
impl<'a, Ctx: Context<'a>, A: InlineableAtomic + Atomic> InlineableFactory<'a, Ctx>
|
||||
for AtomicFactory<A>
|
||||
impl<'a, Ctx: Context<'a>, A: InlineableAtomic> InlineableFactory<'a, Ctx> for AtomicFactory<A>
|
||||
where
|
||||
<A as WithParseMode>::WithMode: AoProxy<'a, Ctx, Fctr = Self, A = A>,
|
||||
{
|
||||
fn extension_error(&self, tail: &[u8]) -> Self::ParseError {
|
||||
A::a_extension_error(tail)
|
||||
@ -72,20 +73,25 @@ impl<'a, Ctx: Context<'a>, A: InlineableAtomic + Atomic> InlineableFactory<'a, C
|
||||
|
||||
fn ideserialize<I: InCtx<'a, Ctx>>(&self, inctx: I) -> IParseResult<'a, Ctx, Self, I> {
|
||||
let (a, inctx) = A::a_ideserialize(inctx)?;
|
||||
Ok((a.into(), inctx))
|
||||
Ok((
|
||||
<<A as WithParseMode>::WithMode as AoProxy<'a, Ctx>>::wrap(a),
|
||||
inctx,
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, Ctx: Context<'a>, A: ConstSizeAtomic + Atomic> FixedSizeFactory<'a, Ctx>
|
||||
for AtomicFactory<A>
|
||||
impl<'a, Ctx: Context<'a>, A: ConstSizeAtomic> FixedSizeFactory<'a, Ctx> for AtomicFactory<A>
|
||||
where
|
||||
<A as WithParseMode>::WithMode: AoProxy<'a, Ctx, Fctr = Self, A = A>,
|
||||
{
|
||||
fn size(&self) -> usize {
|
||||
A::SIZE
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, Ctx: Context<'a>, A: ConstSizeAtomic + Atomic> ConstSizeFactory<'a, Ctx>
|
||||
for AtomicFactory<A>
|
||||
impl<'a, Ctx: Context<'a>, A: ConstSizeAtomic> ConstSizeFactory<'a, Ctx> for AtomicFactory<A>
|
||||
where
|
||||
<A as WithParseMode>::WithMode: AoProxy<'a, Ctx, Fctr = Self, A = A>,
|
||||
{
|
||||
const SIZE: usize = A::SIZE;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user