diff --git a/src/rcore.rs b/src/rcore.rs index 4bcbe3e..90f6a3d 100644 --- a/src/rcore.rs +++ b/src/rcore.rs @@ -73,13 +73,13 @@ pub trait MentionableTop<'a, Ctx: Context<'a>>: 'a { pub trait Mentionable<'a, Ctx: Context<'a>>: MentionableBase<'a, Ctx, Fctr = Self::_Fctr> + MentionableTop<'a, Ctx> { - type _Fctr: Factory<'a, Ctx, Mtbl = Self>; + type _Fctr: Factory<'a, Ctx, _Mtbl = Self>; } impl<'a, Ctx: Context<'a>, A: MentionableBase<'a, Ctx> + MentionableTop<'a, Ctx>> Mentionable<'a, Ctx> for A where - Self::Fctr: Factory<'a, Ctx>, + Self::Fctr: Factory<'a, Ctx, _Mtbl = Self>, { type _Fctr = Self::Fctr; } @@ -96,14 +96,18 @@ pub type ParseResultA<'a, Ctx, A> = Result>; /// [Factory] base. pub trait FactoryBase<'a, Ctx: Context<'a>>: 'a + Send + Sync + Clone { /// Type of the associated objects. - type Mtbl: MentionableBase<'a, Ctx, Fctr = Self> + MentionableTop<'a, Ctx>; + type Mtbl: MentionableBase<'a, Ctx, Fctr = Self>; /// Type of an error that [`Factory::deserialize`] can fail with. type ParseError: 'a + Error; } /// Trait representing deserialisation rules for [Mentionable]s. /// Crucial for [`crate::rstd::typeless`]. -pub trait Factory<'a, Ctx: Context<'a>>: FactoryBase<'a, Ctx> + ParseMode { +pub trait Factory<'a, Ctx: Context<'a>>: + FactoryBase<'a, Ctx, Mtbl = Self::_Mtbl> + ParseMode +{ + type _Mtbl: MentionableBase<'a, Ctx, Fctr = Self> + MentionableTop<'a, Ctx>; + /// See [`Deserializer`], [`Resolver`]. fn deserialize(&self, inctx: impl InCtx<'a, Ctx>) -> ParseResult<'a, Ctx, Self>; /// Called by finite stream parsers if there's any data left. diff --git a/src/rcore/modes.rs b/src/rcore/modes.rs index 2a3eaad..eeb5679 100644 --- a/src/rcore/modes.rs +++ b/src/rcore/modes.rs @@ -30,7 +30,10 @@ pub trait FactoryProxy<'a, Ctx: Context<'a>> { impl<'a, Ctx: Context<'a>, F: FactoryBase<'a, Ctx> + WithParseMode> Factory<'a, Ctx> for F where F::WithMode: FactoryProxy<'a, Ctx, F = Self>, + F::Mtbl: MentionableTop<'a, Ctx>, { + type _Mtbl = Self::Mtbl; + fn deserialize(&self, inctx: impl InCtx<'a, Ctx>) -> ParseResult<'a, Ctx, Self> { >::pdeserialize(self, inctx) } diff --git a/src/rstd/atomic/atomic_object.rs b/src/rstd/atomic/atomic_object.rs index cec52d0..c8ab5bd 100644 --- a/src/rstd/atomic/atomic_object.rs +++ b/src/rstd/atomic/atomic_object.rs @@ -38,7 +38,7 @@ impl Serializable for AtomicObject { pub trait AoProxy<'a, Ctx: Context<'a>>: AtomicProxy { type Mtbl: MentionableBase<'a, Ctx, Fctr = Self::Fctr> + MentionableTop<'a, Ctx>; - type Fctr: Factory<'a, Ctx, Mtbl = Self::Mtbl>; + type Fctr: Factory<'a, Ctx, _Mtbl = Self::Mtbl>; fn factory() -> Self::Fctr; fn wrap(a: Self::A) -> Self::Mtbl; diff --git a/src/rstd/collections/stack.rs b/src/rstd/collections/stack.rs index 36391f0..3512786 100644 --- a/src/rstd/collections/stack.rs +++ b/src/rstd/collections/stack.rs @@ -58,6 +58,8 @@ where impl<'a, Ctx: Context<'a>, F: RegularFactory<'a, Ctx>> StackCompatibleProxy<'a, Ctx, Stack<'a, Ctx, Mtbl<'a, Ctx, F>>> for WithMode +where + F::Mtbl: MentionableTop<'a, Ctx>, { fn points_typed_rest( stack: &Stack<'a, Ctx, Mtbl<'a, Ctx, Self::F>>, @@ -69,6 +71,8 @@ impl<'a, Ctx: Context<'a>, F: RegularFactory<'a, Ctx>> impl<'a, Ctx: Context<'a>, F: InlineableFactory<'a, Ctx>> StackCompatibleProxy<'a, Ctx, Stack<'a, Ctx, Mtbl<'a, Ctx, F>>> for WithMode +where + F::Mtbl: MentionableTop<'a, Ctx>, { fn points_typed_rest( stack: &Stack<'a, Ctx, Mtbl<'a, Ctx, Self::F>>, @@ -151,6 +155,8 @@ impl ParseMode for StackNodeFactory { impl<'a, Ctx: Context<'a>, F: RegularFactory<'a, Ctx>> RegularFactory<'a, Ctx> for StackNodeFactory +where + F::Mtbl: MentionableTop<'a, Ctx>, { fn rdeserialize(&self, inctx: impl InCtx<'a, Ctx>) -> ParseResult<'a, Ctx, Self> { let (rest, inctx) = self.parse_point(inctx)?; @@ -180,7 +186,7 @@ pub type StackVecResult<'a, Ctx, A> = Result, StackFaiure<'a, Ctx, A>>; pub type StackVecWrapped<'a, Ctx, A> = Wrapped<'a, Ctx, StackVecResult<'a, Ctx, A>>; /// Extention trait with helper methods for [Stack]s. -pub trait ExtStack<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>>: +pub trait ExtStack<'a, Ctx: Context<'a>, A: MentionableBase<'a, Ctx>>: MentionableBase<'a, Ctx> { /// Get an empty stack ([`Nullable::Null`]). @@ -201,9 +207,10 @@ pub trait ExtStackClone<'a, Ctx: Context<'a>, A: StackCompatible<'a, Ctx> + Clon fn vec(self) -> StackVecWrapped<'a, Ctx, A>; } -impl<'a, Ctx: Context<'a>, A: StackCompatible<'a, Ctx>> ExtStack<'a, Ctx, A> for Stack<'a, Ctx, A> +impl<'a, Ctx: Context<'a>, A: StackCompatible<'a, Ctx> + Mentionable<'a, Ctx>> ExtStack<'a, Ctx, A> + for Stack<'a, Ctx, A> where - Fctr<'a, Ctx, StackNode<'a, Ctx, A>>: Factory<'a, Ctx>, + StackNode<'a, Ctx, A>: Mentionable<'a, Ctx, _Fctr = StackNodeFactory>, { fn empty(factory: A::Fctr) -> Self { Nullable::Null(StackNodeFactory::new(factory.clone())) @@ -222,10 +229,10 @@ where } } -impl<'a, Ctx: Context<'a>, A: StackCompatible<'a, Ctx> + Clone> ExtStackClone<'a, Ctx, A> - for Stack<'a, Ctx, A> +impl<'a, Ctx: Context<'a>, A: StackCompatible<'a, Ctx> + Mentionable<'a, Ctx> + Clone> + ExtStackClone<'a, Ctx, A> for Stack<'a, Ctx, A> where - Fctr<'a, Ctx, StackNode<'a, Ctx, A>>: Factory<'a, Ctx>, + StackNode<'a, Ctx, A>: Mentionable<'a, Ctx, _Fctr = StackNodeFactory>, { fn vec(self) -> StackVecWrapped<'a, Ctx, A> { Ctx::T::iterate_mut((vec![], self), |(mut vec, stack)| match stack { @@ -246,6 +253,8 @@ where impl<'a, Ctx: Context<'a>, F: InlineableFactory<'a, Ctx>> InlineableFactory<'a, Ctx> for StackNodeFactory +where + F::Mtbl: MentionableTop<'a, Ctx>, { fn extension_error(&self, tail: &[u8]) -> Self::ParseError { StackParseError::Element(self.element_factory.extension_error(tail)) @@ -263,6 +272,8 @@ impl<'a, Ctx: Context<'a>, F: InlineableFactory<'a, Ctx>> InlineableFactory<'a, impl<'a, Ctx: Context<'a>, F: FixedSizeFactory<'a, Ctx>> FixedSizeFactory<'a, Ctx> for StackNodeFactory +where + F::Mtbl: MentionableTop<'a, Ctx>, { fn size(&self) -> usize { Stack::<'a, Ctx, F::Mtbl>::SIZE + self.element_factory.size() @@ -271,6 +282,8 @@ impl<'a, Ctx: Context<'a>, F: FixedSizeFactory<'a, Ctx>> FixedSizeFactory<'a, Ct impl<'a, Ctx: Context<'a>, F: ConstSizeFactory<'a, Ctx>> ConstSizeFactory<'a, Ctx> for StackNodeFactory +where + F::Mtbl: MentionableTop<'a, Ctx>, { const SIZE: usize = Stack::<'a, Ctx, F::Mtbl>::SIZE + F::SIZE; } diff --git a/src/rstd/nullable.rs b/src/rstd/nullable.rs index 411361c..7b2b253 100644 --- a/src/rstd/nullable.rs +++ b/src/rstd/nullable.rs @@ -28,7 +28,7 @@ impl<'a, Ctx: Context<'a>, A: MentionableBase<'a, Ctx>> Serializable for Nullabl } } -impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> MentionableBase<'a, Ctx> +impl<'a, Ctx: Context<'a>, A: MentionableBase<'a, Ctx>> MentionableBase<'a, Ctx> for Nullable<'a, Ctx, A> { type Fctr = NullableFactory; @@ -56,7 +56,7 @@ impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> MentionableTop<'a, Ctx> } } -impl<'a, Ctx: Context<'a>, F: Factory<'a, Ctx>> FactoryBase<'a, Ctx> for NullableFactory { +impl<'a, Ctx: Context<'a>, F: FactoryBase<'a, Ctx>> FactoryBase<'a, Ctx> for NullableFactory { type Mtbl = Nullable<'a, Ctx, F::Mtbl>; type ParseError = PointParseError; diff --git a/src/rstd/point.rs b/src/rstd/point.rs index e290df4..f819dd4 100644 --- a/src/rstd/point.rs +++ b/src/rstd/point.rs @@ -11,7 +11,9 @@ impl<'a, Ctx: Context<'a>, A: MentionableBase<'a, Ctx>> Serializable for Point<' } } -impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> MentionableBase<'a, Ctx> for Point<'a, Ctx, A> { +impl<'a, Ctx: Context<'a>, A: MentionableBase<'a, Ctx>> MentionableBase<'a, Ctx> + for Point<'a, Ctx, A> +{ type Fctr = PointFactory; fn factory(&self) -> Self::Fctr { @@ -71,7 +73,7 @@ impl<'a, Ctx: Context<'a>, A: MentionableBase<'a, Ctx>> AsRef<[u8]> for Point<'a } } -impl<'a, Ctx: Context<'a>, F: Factory<'a, Ctx>> FactoryBase<'a, Ctx> for PointFactory { +impl<'a, Ctx: Context<'a>, F: FactoryBase<'a, Ctx>> FactoryBase<'a, Ctx> for PointFactory { type Mtbl = Point<'a, Ctx, F::Mtbl>; type ParseError = PointParseError; diff --git a/src/rstd/wrapped_origin.rs b/src/rstd/wrapped_origin.rs index 72ceca2..2641695 100644 --- a/src/rstd/wrapped_origin.rs +++ b/src/rstd/wrapped_origin.rs @@ -26,7 +26,7 @@ pub trait MappableOrigin<'a, Ctx: Context<'a>>: Origin<'a, Ctx> { map_factory: impl 'a + FnOnce(OFctr<'a, Ctx, Self>) -> B::Fctr, ) -> Rc> where - OFctr<'a, Ctx, Self>: Factory<'a, Ctx>, + OFctr<'a, Ctx, Self>: Factory<'a, Ctx, _Mtbl = Self::Mtbl>, Self::Mtbl: MentionableTop<'a, Ctx>, { let origin_r = self.clone();