diff --git a/src/rcore.rs b/src/rcore.rs index 38b2e28..2365fc0 100644 --- a/src/rcore.rs +++ b/src/rcore.rs @@ -46,9 +46,9 @@ pub use self::resolution::{ pub type Wrapped<'a, Ctx, A> = WrapC<'a, A, Ctx>; /// [Mentionable] base. -pub trait MentionableBase<'a, Ctx: Context<'a>>: 'a + Send + Sync + Serializable + Sized { +pub trait MentionableBase<'a>: 'a + Send + Sync + Serializable + Sized { /// Type of the associated factory. - type Fctr: FactoryBase<'a, Ctx, Mtbl = Self>; + type Fctr: FactoryBase<'a, Mtbl = Self>; /// Value of the associated factory. fn factory(&self) -> Self::Fctr; @@ -75,13 +75,13 @@ pub trait MentionableTop<'a, Ctx: Context<'a>>: 'a { /// Fundamental trait for ADN objects. pub trait Mentionable<'a, Ctx: Context<'a>>: - MentionableBase<'a, Ctx, Fctr = Self::_Fctr> + MentionableTop<'a, Ctx> + MentionableBase<'a, Fctr = Self::_Fctr> + MentionableTop<'a, Ctx> { type _Fctr: Factory<'a, Ctx, _Mtbl = Self>; } -impl<'a, Ctx: Context<'a>, A: MentionableBase<'a, Ctx> + MentionableTop<'a, Ctx>> - Mentionable<'a, Ctx> for A +impl<'a, Ctx: Context<'a>, A: MentionableBase<'a> + MentionableTop<'a, Ctx>> Mentionable<'a, Ctx> + for A where Self::Fctr: Factory<'a, Ctx, _Mtbl = Self>, { @@ -89,18 +89,18 @@ where } /// [`Factory`] associated with the [`Mentionable`]. Mostly useful for `type` definitions. -pub type Fctr<'a, Ctx, A> = >::Fctr; +pub type Fctr<'a, A> = >::Fctr; /// Shorthand for the type of values returned by [`FactoryParse::deserialize`]. -pub type ParseResult<'a, Ctx, F> = Result, ParseError<'a, Ctx, F>>; +pub type ParseResult<'a, F> = Result, ParseError<'a, F>>; /// [`ParseResult`] associated with a [`Mentionable`] (instead of a [`Factory`]). -pub type ParseResultA<'a, Ctx, A> = Result>; +pub type ParseResultA<'a, A> = Result>; /// [Factory] base. -pub trait FactoryBase<'a, Ctx: Context<'a>>: 'a + Send + Sync + Clone { +pub trait FactoryBase<'a>: 'a + Send + Sync + Clone { /// Type of the associated objects. - type Mtbl: MentionableBase<'a, Ctx, Fctr = Self>; + type Mtbl: MentionableBase<'a, Fctr = Self>; /// Type of an error that [`FactoryParse::deserialize`] can fail with. type ParseError: 'a + Send + Error; } @@ -108,9 +108,9 @@ pub trait FactoryBase<'a, Ctx: Context<'a>>: 'a + Send + Sync + Clone { /// [Factory] that allows parsing consuming the parser. pub trait FactoryParse<'a, Ctx: Context<'a>>: FactoryModeParse<'a, Ctx> { /// Consumes the parser. See [`Deserializer`], [`Resolver`]. - fn deserialize(&self, inctx: impl InCtx<'a, Ctx>) -> ParseResult<'a, Ctx, Self>; + fn deserialize(&self, inctx: impl InCtx<'a, Ctx>) -> ParseResult<'a, Self>; /// Called by finite stream parsers if there's any data left. - fn extend(&self, mentionable: Self::Mtbl, tail: &[u8]) -> ParseResult<'a, Ctx, Self>; + fn extend(&self, mentionable: Self::Mtbl, tail: &[u8]) -> ParseResult<'a, Self>; } /// Trait representing deserialisation rules for [Mentionable]s. @@ -120,18 +120,18 @@ pub trait FactoryParse<'a, Ctx: Context<'a>>: FactoryModeParse<'a, Ctx> { pub trait Factory<'a, Ctx: Context<'a>>: FactoryParse<'a, Ctx, Mtbl = Self::_Mtbl> + ParseMode { - type _Mtbl: MentionableBase<'a, Ctx, Fctr = Self> + MentionableTop<'a, Ctx>; + type _Mtbl: MentionableBase<'a, Fctr = Self> + MentionableTop<'a, Ctx>; } /// [`Mentionable`] associated with the [`Factory`]. Mostly useful for `type` definitions. -pub type Mtbl<'a, Ctx, F> = >::Mtbl; +pub type Mtbl<'a, F> = >::Mtbl; /// [`FactoryBase::ParseError`]. Mostly useful for `type` definitions. -pub type ParseError<'a, Ctx, F> = >::ParseError; +pub type ParseError<'a, F> = >::ParseError; /// [`FactoryBase::ParseError`] associated with the [`Mentionable`]. /// Mostly useful for `type` definitions. -pub type ParseErrorA<'a, Ctx, A> = ParseError<'a, Ctx, Fctr<'a, Ctx, A>>; +pub type ParseErrorA<'a, A> = ParseError<'a, Fctr<'a, A>>; /// Extension trait for factories. pub trait FactoryExt<'a, Ctx: Context<'a>>: FactoryParse<'a, Ctx> { @@ -140,5 +140,5 @@ pub trait FactoryExt<'a, Ctx: Context<'a>>: FactoryParse<'a, Ctx> { &self, slice: &[u8], resolver: &Arc>, - ) -> ParseResult<'a, Ctx, Self>; + ) -> ParseResult<'a, Self>; } diff --git a/src/rcore/addresses.rs b/src/rcore/addresses.rs index 0c02394..0ce3e4e 100644 --- a/src/rcore/addresses.rs +++ b/src/rcore/addresses.rs @@ -44,7 +44,7 @@ pub(super) trait InliningAddresses: Stream { Ok((address, deserializer)) } - fn inext_point<'a, Ctx: Context<'a>, A: MentionableBase<'a, Ctx>>( + fn inext_point<'a, Ctx: Context<'a>, A: MentionableBase<'a>>( self, addresses: &mut Addresses, resolver: Arc>, @@ -62,7 +62,7 @@ fn _parse_slice<'a, Ctx: Context<'a>, F: FactoryParse<'a, Ctx>>( factory: &F, slice: &[u8], resolver: &Arc>, -) -> ParseResult<'a, Ctx, F> { +) -> ParseResult<'a, F> { let mut deserializer = SliceDeserializer::from(slice); let mentionable = factory.deserialize(&mut DeCtxT { deserializer: &mut deserializer, @@ -82,7 +82,7 @@ impl<'a, Ctx: Context<'a>, F: FactoryParse<'a, Ctx>> FactoryExt<'a, Ctx> for F { &self, slice: &[u8], resolver: &Arc>, - ) -> ParseResult<'a, Ctx, Self> { + ) -> ParseResult<'a, Self> { _parse_slice::(self, slice, resolver) } } diff --git a/src/rcore/context.rs b/src/rcore/context.rs index 84e66c1..f43f36e 100644 --- a/src/rcore/context.rs +++ b/src/rcore/context.rs @@ -1,7 +1,7 @@ use super::*; /// Execution context. -pub trait Context<'a>: FallibleCtx<'a, T = Self::_Tm> { +pub trait Context<'a>: FallibleCtx<'a, T = Self::_Tm> + Send + Sync { /// Type to provide for [Monad]ic representation of computation, mostly that of resolution ([`Resolution`]). type _Tm: Monad<'a>; diff --git a/src/rcore/demoted.rs b/src/rcore/demoted.rs index 1d5c69f..607bced 100644 --- a/src/rcore/demoted.rs +++ b/src/rcore/demoted.rs @@ -29,7 +29,7 @@ impl<'a: 'c, 'c, Ctx: Context<'a>> InCtx<'a, Ctx> for Demoted<'a, 'c, Ctx> { Ok((address, Self(dectx))) } - fn icnext_point<'b, A: MentionableBase<'a, Ctx>, E>( + fn icnext_point<'b, A: MentionableBase<'a>, E>( self, factory: A::Fctr, err: impl FnOnce(&[u8]) -> E, diff --git a/src/rcore/inctx.rs b/src/rcore/inctx.rs index ddfa56c..814a410 100644 --- a/src/rcore/inctx.rs +++ b/src/rcore/inctx.rs @@ -6,7 +6,7 @@ pub trait InCtx<'a, Ctx: Context<'a>>: Stream { fn icnext_address(self, err: impl FnOnce(&[u8]) -> E) -> Result<(Address, Self), E>; /// Read the next [Point]. - fn icnext_point<'b, A: MentionableBase<'a, Ctx>, E>( + fn icnext_point<'b, A: MentionableBase<'a>, E>( self, factory: A::Fctr, err: impl FnOnce(&[u8]) -> E, diff --git a/src/rcore/inlining.rs b/src/rcore/inlining.rs index 13d12ce..7bee534 100644 --- a/src/rcore/inlining.rs +++ b/src/rcore/inlining.rs @@ -1,29 +1,29 @@ use super::*; /// Inlining version of [`ParseResult`]. Preserves the parser. -pub type IParseResult<'a, Ctx, F, I> = Result<(Mtbl<'a, Ctx, F>, I), ParseError<'a, Ctx, F>>; +pub type IParseResult<'a, F, I> = Result<(Mtbl<'a, F>, I), ParseError<'a, F>>; /// For auto-deriving [`InliningFactory`] from concrete implementations. pub trait CInliningFactory<'a, Ctx: Context<'a>>: - FactoryBase<'a, Ctx> + ImplMode + FactoryBase<'a> + ImplMode { /// Concrete implementation of [`InliningFactory::extension_error`]. fn cextension_error(&self, tail: &[u8]) -> Self::ParseError; /// Concrete implementation of [`InliningFactory::ideserialize`]. - fn cideserialize>(&self, inctx: I) -> IParseResult<'a, Ctx, Self, I>; + fn cideserialize>(&self, inctx: I) -> IParseResult<'a, Self, I>; } /// Factory preserving the parser on success. pub trait InliningFactory<'a, Ctx: Context<'a>>: - FactoryBase<'a, Ctx> + ParseMode + FactoryBase<'a> + ParseMode { /// Always fail on extension, /// as parsing of an inlining object should be determined without reaching EOF. fn extension_error(&self, tail: &[u8]) -> Self::ParseError; /// Inlining version of [`FactoryParse::deserialize`]. Preserves the parser. - fn ideserialize>(&self, inctx: I) -> IParseResult<'a, Ctx, Self, I>; + fn ideserialize>(&self, inctx: I) -> IParseResult<'a, Self, I>; } impl<'a, Ctx: Context<'a>, F: FactoryModeParse<'a, Ctx> + ParseMode> @@ -33,7 +33,7 @@ impl<'a, Ctx: Context<'a>, F: FactoryModeParse<'a, Ctx> + ParseMode>(&self, inctx: I) -> IParseResult<'a, Ctx, Self, I> { + fn ideserialize>(&self, inctx: I) -> IParseResult<'a, Self, I> { self.mdeserialize(inctx) } } @@ -43,15 +43,15 @@ impl<'a, Ctx: Context<'a>, F: CInliningFactory<'a, Ctx>> FactoryModeProxy<'a, Ct { type F = F; - fn pmdeserialize>(f: &Self::F, inctx: I) -> ModeResultM<'a, Ctx, F, I> { + fn pmdeserialize>(f: &Self::F, inctx: I) -> ModeResultM<'a, F, I> { f.cideserialize(inctx) } fn pmextend( f: &F, - _mentionable: ExtensionSourceM<'a, Ctx, F>, + _mentionable: ExtensionSourceM<'a, F>, tail: &[u8], - ) -> ExtensionResultM<'a, Ctx, F> { + ) -> ExtensionResultM<'a, F> { f.cextension_error(tail) } } diff --git a/src/rcore/modes.rs b/src/rcore/modes.rs index d9a55a4..594b3ad 100644 --- a/src/rcore/modes.rs +++ b/src/rcore/modes.rs @@ -1,11 +1,11 @@ use super::*; impl<'a, Ctx: Context<'a>, F: FactoryModeParse<'a, Ctx>> FactoryParse<'a, Ctx> for F { - fn deserialize(&self, inctx: impl InCtx<'a, Ctx>) -> ParseResult<'a, Ctx, Self> { + fn deserialize(&self, inctx: impl InCtx<'a, Ctx>) -> ParseResult<'a, Self> { self.mdeserialize(inctx).map(Self::seal) } - fn extend(&self, mentionable: Self::Mtbl, tail: &[u8]) -> ParseResult<'a, Ctx, Self> { + fn extend(&self, mentionable: Self::Mtbl, tail: &[u8]) -> ParseResult<'a, Self> { Self::xseal(self.mextend(Self::prepare(mentionable), tail)) } } @@ -18,57 +18,56 @@ where } /// [`FactoryParse`] equivalent of [`ModeResult`]. -pub type ModeResultM<'a, Ctx, F, I> = ModeResultP, ParseError<'a, Ctx, F>, I>; +pub type ModeResultM<'a, F, I> = ModeResultP, ParseError<'a, F>, I>; /// [`FactoryParse`] equivalent of [`ExtensionResult`]. -pub type ExtensionResultM<'a, Ctx, F> = - ExtensionResultP, ParseError<'a, Ctx, F>>; +pub type ExtensionResultM<'a, F> = ExtensionResultP, ParseError<'a, F>>; /// [`FactoryParse`] equivalent of [`ExtensionSource`]. -pub type ExtensionSourceM<'a, Ctx, F> = ExtensionSourceP>; +pub type ExtensionSourceM<'a, F> = ExtensionSourceP>; /// A more generic version of [`FactoryParse`]. -pub trait FactoryModeParse<'a, Ctx: Context<'a>>: FactoryBase<'a, Ctx> + ParseMode { +pub trait FactoryModeParse<'a, Ctx: Context<'a>>: FactoryBase<'a> + ParseMode { /// A more generic version of [`FactoryParse::deserialize`]. - fn mdeserialize>(&self, inctx: I) -> ModeResultM<'a, Ctx, Self, I>; + fn mdeserialize>(&self, inctx: I) -> ModeResultM<'a, Self, I>; /// A more generic version of [`FactoryParse::extend`]. fn mextend( &self, - mentionable: ExtensionSourceM<'a, Ctx, Self>, + mentionable: ExtensionSourceM<'a, Self>, tail: &[u8], - ) -> ExtensionResultM<'a, Ctx, Self>; + ) -> ExtensionResultM<'a, Self>; } /// External implementation of [`FactoryModeParse`]. pub trait FactoryModeProxy<'a, Ctx: Context<'a>> { /// Associated [`FactoryModeParse`]. - type F: FactoryBase<'a, Ctx> + ParseMode; + type F: FactoryBase<'a> + ParseMode; /// External implementation of [`FactoryModeParse::mdeserialize`]. - fn pmdeserialize>(f: &Self::F, inctx: I) -> ModeResultM<'a, Ctx, Self::F, I>; + fn pmdeserialize>(f: &Self::F, inctx: I) -> ModeResultM<'a, Self::F, I>; /// External implementation of [`FactoryModeParse::mextend`]. fn pmextend( f: &Self::F, - mentionable: ExtensionSourceM<'a, Ctx, Self::F>, + mentionable: ExtensionSourceM<'a, Self::F>, tail: &[u8], - ) -> ExtensionResultM<'a, Ctx, Self::F>; + ) -> ExtensionResultM<'a, Self::F>; } -impl<'a, Ctx: Context<'a>, F: FactoryBase<'a, Ctx> + WithParseMode> FactoryModeParse<'a, Ctx> for F +impl<'a, Ctx: Context<'a>, F: FactoryBase<'a> + WithParseMode> FactoryModeParse<'a, Ctx> for F where F::WithMode: FactoryModeProxy<'a, Ctx, F = F>, { - fn mdeserialize>(&self, inctx: I) -> ModeResultM<'a, Ctx, Self, I> { + fn mdeserialize>(&self, inctx: I) -> ModeResultM<'a, Self, I> { >::pmdeserialize(self, inctx) } fn mextend( &self, - mentionable: ExtensionSourceM<'a, Ctx, Self>, + mentionable: ExtensionSourceM<'a, Self>, tail: &[u8], - ) -> ExtensionResultM<'a, Ctx, Self> { + ) -> ExtensionResultM<'a, Self> { >::pmextend(self, mentionable, tail) } } diff --git a/src/rcore/origin.rs b/src/rcore/origin.rs index 34378e2..04a11ae 100644 --- a/src/rcore/origin.rs +++ b/src/rcore/origin.rs @@ -3,7 +3,7 @@ use super::*; /// Represents a potentially resolvable [`Mentionable`]. pub trait Origin<'a, Ctx: Context<'a>>: 'a + Send + Sync { /// Type of the associated object. - type Mtbl: MentionableBase<'a, Ctx>; + type Mtbl: MentionableBase<'a>; /// Clone the associated factory. fn factory(&self) -> OFctr<'a, Ctx, Self>; /// Try resolving the value. @@ -15,7 +15,7 @@ pub trait Origin<'a, Ctx: Context<'a>>: 'a + Send + Sync { } /// Type of the [`Factory`] associated with the [`Origin`]. -pub type OFctr<'a, Ctx, O> = Fctr<'a, Ctx, >::Mtbl>; +pub type OFctr<'a, Ctx, O> = Fctr<'a, >::Mtbl>; /// [`OriginMap::resolve_map`]. pub trait OriginMap<'a, Ctx: Context<'a>>: Origin<'a, Ctx> { diff --git a/src/rcore/point.rs b/src/rcore/point.rs index ffc73c6..55e329d 100644 --- a/src/rcore/point.rs +++ b/src/rcore/point.rs @@ -1,7 +1,7 @@ use super::*; /// The main way to represent a reference in ADN. -pub struct Point<'a, Ctx: Context<'a>, A: MentionableBase<'a, Ctx>> { +pub struct Point<'a, Ctx: Context<'a>, A: MentionableBase<'a>> { /// Hash of the referred content. /// Derived both from the serialised value ([`Serializable::serialize`]) /// and its topology ([`MentionableTop::topology`]). @@ -10,14 +10,14 @@ pub struct Point<'a, Ctx: Context<'a>, A: MentionableBase<'a, Ctx>> { pub origin: Arc>, } -impl<'a, Ctx: Context<'a>, A: MentionableBase<'a, Ctx>> PartialEq for Point<'a, Ctx, A> { +impl<'a, Ctx: Context<'a>, A: MentionableBase<'a>> PartialEq for Point<'a, Ctx, A> { /// Note: this doesn't check for [Factory] equality. fn eq(&self, other: &Self) -> bool { self.point == other.point } } -impl<'a, Ctx: Context<'a>, A: MentionableBase<'a, Ctx>> Clone for Point<'a, Ctx, A> { +impl<'a, Ctx: Context<'a>, A: MentionableBase<'a>> Clone for Point<'a, Ctx, A> { fn clone(&self) -> Self { Self { point: self.point, @@ -26,7 +26,7 @@ impl<'a, Ctx: Context<'a>, A: MentionableBase<'a, Ctx>> Clone for Point<'a, Ctx, } } -impl<'a, Ctx: Context<'a>, A: MentionableBase<'a, Ctx>> Point<'a, Ctx, A> +impl<'a, Ctx: Context<'a>, A: MentionableBase<'a>> Point<'a, Ctx, A> where A::Fctr: FactoryParse<'a, Ctx>, { diff --git a/src/rcore/regular.rs b/src/rcore/regular.rs index 8ff7c59..61f79ac 100644 --- a/src/rcore/regular.rs +++ b/src/rcore/regular.rs @@ -2,34 +2,34 @@ use super::*; /// For auto-deriving [`RegularFactory`] from concrete implementations. pub trait CRegularFactory<'a, Ctx: Context<'a>>: - FactoryBase<'a, Ctx> + ImplMode + FactoryBase<'a> + ImplMode { /// Concrete implementation of [`RegularFactory::rdeserialize`]. - fn crdeserialize(&self, inctx: impl InCtx<'a, Ctx>) -> ParseResult<'a, Ctx, Self>; + fn crdeserialize(&self, inctx: impl InCtx<'a, Ctx>) -> ParseResult<'a, Self>; /// Concrete implementation of [`RegularFactory::rextend`]. - fn crextend(&self, mentionable: Self::Mtbl, tail: &[u8]) -> ParseResult<'a, Ctx, Self>; + fn crextend(&self, mentionable: Self::Mtbl, tail: &[u8]) -> ParseResult<'a, Self>; } /// Mostly same as [`FactoryModeParse`] but requires [`Mode`] to be [`RegularMode`]. pub trait RegularFactory<'a, Ctx: Context<'a>>: - FactoryBase<'a, Ctx> + ParseMode + FactoryBase<'a> + ParseMode { /// Same as [`FactoryModeParse::mdeserialize`]. - fn rdeserialize(&self, inctx: impl InCtx<'a, Ctx>) -> ParseResult<'a, Ctx, Self>; + fn rdeserialize(&self, inctx: impl InCtx<'a, Ctx>) -> ParseResult<'a, Self>; /// Same as [`FactoryModeParse::mextend`]. - fn rextend(&self, mentionable: Self::Mtbl, tail: &[u8]) -> ParseResult<'a, Ctx, Self>; + fn rextend(&self, mentionable: Self::Mtbl, tail: &[u8]) -> ParseResult<'a, Self>; } impl<'a, Ctx: Context<'a>, F: FactoryModeParse<'a, Ctx> + ParseMode> RegularFactory<'a, Ctx> for F { - fn rdeserialize(&self, inctx: impl InCtx<'a, Ctx>) -> ParseResult<'a, Ctx, Self> { + fn rdeserialize(&self, inctx: impl InCtx<'a, Ctx>) -> ParseResult<'a, Self> { self.mdeserialize(inctx) } - fn rextend(&self, mentionable: Self::Mtbl, tail: &[u8]) -> ParseResult<'a, Ctx, Self> { + fn rextend(&self, mentionable: Self::Mtbl, tail: &[u8]) -> ParseResult<'a, Self> { self.mextend(mentionable, tail) } } @@ -39,11 +39,11 @@ impl<'a, Ctx: Context<'a>, F: CRegularFactory<'a, Ctx>> FactoryModeProxy<'a, Ctx { type F = F; - fn pmdeserialize>(f: &Self::F, inctx: I) -> ModeResultM<'a, Ctx, F, I> { + fn pmdeserialize>(f: &Self::F, inctx: I) -> ModeResultM<'a, F, I> { f.crdeserialize(inctx) } - fn pmextend(f: &F, mentionable: Mtbl<'a, Ctx, F>, tail: &[u8]) -> ExtensionResultM<'a, Ctx, F> { + fn pmextend(f: &F, mentionable: Mtbl<'a, F>, tail: &[u8]) -> ExtensionResultM<'a, F> { f.crextend(mentionable, tail) } } diff --git a/src/rcore/resolution.rs b/src/rcore/resolution.rs index 68fb25e..1f195db 100644 --- a/src/rcore/resolution.rs +++ b/src/rcore/resolution.rs @@ -23,8 +23,7 @@ impl ResolutionError { pub type LookupError<'a, Ctx> = >::LookupError; /// See [`ResolutionResult`]. -pub type ResolutionFailure<'a, Ctx, A> = - ResolutionError, ParseErrorA<'a, Ctx, A>>; +pub type ResolutionFailure<'a, Ctx, A> = ResolutionError, ParseErrorA<'a, A>>; /// Result yielded by [`Origin`]. pub type ResolutionResult<'a, Ctx, A> = Result, ResolutionFailure<'a, Ctx, A>>; diff --git a/src/rcore/resolver_origin.rs b/src/rcore/resolver_origin.rs index 4dd299b..fecbb65 100644 --- a/src/rcore/resolver_origin.rs +++ b/src/rcore/resolver_origin.rs @@ -1,9 +1,6 @@ use super::*; -impl<'a, Ctx: Context<'a>, A: MentionableBase<'a, Ctx>> Point<'a, Ctx, A> -where - A::Fctr: FactoryBase<'a, Ctx>, -{ +impl<'a, Ctx: Context<'a>, A: MentionableBase<'a>> Point<'a, Ctx, A> { /// Make a [Point] from an [Address]. pub fn from_address( address: Address, @@ -21,7 +18,7 @@ where } } -struct ResolverOrigin<'a, Ctx: Context<'a>, F: FactoryBase<'a, Ctx>> { +struct ResolverOrigin<'a, Ctx: Context<'a>, F: FactoryBase<'a>> { r_factory: F, r_address: Address, r_resolver: Arc>, @@ -43,7 +40,7 @@ fn _resolve_origin<'a, Ctx: Context<'a>, F: FactoryParse<'a, Ctx>>( }) } -impl<'a, Ctx: Context<'a>, F: FactoryBase<'a, Ctx>> Origin<'a, Ctx> for ResolverOrigin<'a, Ctx, F> { +impl<'a, Ctx: Context<'a>, F: FactoryBase<'a>> Origin<'a, Ctx> for ResolverOrigin<'a, Ctx, F> { type Mtbl = F::Mtbl; fn factory(&self) -> OFctr<'a, Ctx, Self> { diff --git a/src/rstd/atomic_object.rs b/src/rstd/atomic_object.rs index 819975a..b2c2421 100644 --- a/src/rstd/atomic_object.rs +++ b/src/rstd/atomic_object.rs @@ -38,7 +38,7 @@ impl Serializable for AtomicObject { } } -impl<'a, Ctx: Context<'a>, A: AtomicBase> MentionableBase<'a, Ctx> for AtomicObject { +impl<'a, A: AtomicBase> MentionableBase<'a> for AtomicObject { type Fctr = AtomicFactory; fn factory(&self) -> Self::Fctr { @@ -71,7 +71,7 @@ impl Clone for AtomicFactory { } } -impl<'a, Ctx: Context<'a>, A: AtomicBase> FactoryBase<'a, Ctx> for AtomicFactory { +impl<'a, A: AtomicBase> FactoryBase<'a> for AtomicFactory { type Mtbl = AtomicObject; type ParseError = A::AParseError; @@ -82,15 +82,15 @@ impl ParseMode for AtomicFactory { } impl<'a, Ctx: Context<'a>, A: AtomicModeParse> FactoryModeParse<'a, Ctx> for AtomicFactory { - fn mdeserialize>(&self, inctx: I) -> ModeResultM<'a, Ctx, Self, I> { + fn mdeserialize>(&self, inctx: I) -> ModeResultM<'a, Self, I> { A::ma_deserialize(inctx).map(|a| Self::map(a, From::from)) } fn mextend( &self, - mentionable: ExtensionSourceM<'a, Ctx, Self>, + mentionable: ExtensionSourceM<'a, Self>, tail: &[u8], - ) -> ExtensionResultM<'a, Ctx, Self> { + ) -> ExtensionResultM<'a, Self> { Self::xbind( A::ma_extend(Self::smap(mentionable, |a| a.atomic), tail), |a| Ok(a.into()), diff --git a/src/rstd/cast.rs b/src/rstd/cast.rs index a67fca7..a8959c4 100644 --- a/src/rstd/cast.rs +++ b/src/rstd/cast.rs @@ -152,7 +152,7 @@ impl<'a, Ctx: CastCtx<'a>> TypelessMentionable<'a, Ctx> { &self, factory: A::Fctr, map_resolver: impl FnOnce(Arc>) -> Arc>, - ) -> ParseResultA<'a, Ctx, A> { + ) -> ParseResultA<'a, A> { factory.parse_slice( &self.bytes(), &map_resolver(CastResolver::rc(self.points_vec())), @@ -160,7 +160,7 @@ impl<'a, Ctx: CastCtx<'a>> TypelessMentionable<'a, Ctx> { } /// Re-parse the object as if it is of a specific type. Has potential to break topology. - pub fn cast>(&self, factory: A::Fctr) -> ParseResultA<'a, Ctx, A> { + pub fn cast>(&self, factory: A::Fctr) -> ParseResultA<'a, A> { self.cast_full(factory, identity) } } diff --git a/src/rstd/collections/pair.rs b/src/rstd/collections/pair.rs index 74f5115..6a40b38 100644 --- a/src/rstd/collections/pair.rs +++ b/src/rstd/collections/pair.rs @@ -10,7 +10,7 @@ use crate::rstd::inlining::static_pair::*; use crate::rstd::inlining::*; pub type PairObject = StaticPairObject<(A, B)>; -pub type PairFactory<'a, Ctx, A, B> = StaticPairFactory<'a, Ctx, (A, B)>; +pub type PairFactory<'a, A, B> = StaticPairFactory<'a, (A, B)>; impl StaticPairSerializable for (A, B) { type SA = A; @@ -46,8 +46,7 @@ impl Display for PairParseError { impl Error for PairParseError {} -impl<'a, Ctx: Context<'a>, A: MentionableBase<'a, Ctx>, B: MentionableBase<'a, Ctx>> - StaticPair<'a, Ctx> for (A, B) +impl<'a, A: MentionableBase<'a>, B: MentionableBase<'a>> StaticPair<'a> for (A, B) where A::Fctr: ParseMode, B::Fctr: ParseMode, @@ -57,7 +56,7 @@ where type B = B; type FA = A::Fctr; type FB = B::Fctr; - type ParseError = PairParseError, ParseError<'a, Ctx, B::Fctr>>; + type ParseError = PairParseError, ParseError<'a, B::Fctr>>; fn factories(factory_data: &Self::FactoryData) -> (&Self::FA, &Self::FB) { (&factory_data.0, &factory_data.1) @@ -73,14 +72,14 @@ where fn from_error_a( _factory_data: &Self::FactoryData, - error: ParseError<'a, Ctx, Self::FA>, + error: ParseError<'a, Self::FA>, ) -> Self::ParseError { PairParseError::A(error) } fn from_error_b( _factory_data: &Self::FactoryData, - error: ParseError<'a, Ctx, Self::FB>, + error: ParseError<'a, Self::FB>, ) -> Self::ParseError { PairParseError::B(error) } @@ -115,9 +114,7 @@ impl Serializable for (A, B) { } } -impl<'a, Ctx: Context<'a>, A: MentionableBase<'a, Ctx>, B: MentionableBase<'a, Ctx>> - MentionableBase<'a, Ctx> for (A, B) -{ +impl<'a, A: MentionableBase<'a>, B: MentionableBase<'a>> MentionableBase<'a> for (A, B) { type Fctr = (A::Fctr, B::Fctr); fn factory(&self) -> Self::Fctr { @@ -125,9 +122,7 @@ impl<'a, Ctx: Context<'a>, A: MentionableBase<'a, Ctx>, B: MentionableBase<'a, C } } -impl<'a, Ctx: Context<'a>, FA: FactoryBase<'a, Ctx>, FB: FactoryBase<'a, Ctx>> FactoryBase<'a, Ctx> - for (FA, FB) -{ +impl<'a, FA: FactoryBase<'a>, FB: FactoryBase<'a>> FactoryBase<'a> for (FA, FB) { type Mtbl = (FA::Mtbl, FB::Mtbl); type ParseError = PairParseError; @@ -141,28 +136,22 @@ impl ParseMode for (A, B) { type Mode = B::Mode; } -type PFImpl<'a, Ctx, FA, FB> = StaticPairFactory< - 'a, - Ctx, - ( - >::Mtbl, - >::Mtbl, - ), ->; +type PFImpl<'a, FA, FB> = + StaticPairFactory<'a, (>::Mtbl, >::Mtbl)>; impl<'a, Ctx: Context<'a>, FA: InliningFactory<'a, Ctx>, FB: FactoryModeParse<'a, Ctx>> FactoryModeParse<'a, Ctx> for (FA, FB) { - fn mdeserialize>(&self, inctx: I) -> ModeResultM<'a, Ctx, Self, I> { - PFImpl::<'a, Ctx, FA, FB>::mdeserialize_sp(self, inctx) + fn mdeserialize>(&self, inctx: I) -> ModeResultM<'a, Self, I> { + PFImpl::<'a, FA, FB>::mdeserialize_sp(self, inctx) } fn mextend( &self, - mentionable: ExtensionSourceM<'a, Ctx, Self>, + mentionable: ExtensionSourceM<'a, Self>, tail: &[u8], - ) -> ExtensionResultM<'a, Ctx, Self> { - PFImpl::<'a, Ctx, FA, FB>::mextend_sp(self, mentionable, tail) + ) -> ExtensionResultM<'a, Self> { + PFImpl::<'a, FA, FB>::mextend_sp(self, mentionable, tail) } } diff --git a/src/rstd/collections/stack.rs b/src/rstd/collections/stack.rs index cdd840a..9c1f3a8 100644 --- a/src/rstd/collections/stack.rs +++ b/src/rstd/collections/stack.rs @@ -1,12 +1,14 @@ //! Basic implementation of a stack/linked list. +use std::marker::PhantomData; + use crate::func::{context::*, controlflow::ControlFlow}; use crate::mode::*; use crate::rcore::*; use crate::rstd::{inlining::*, nullable::*, point::*, *}; /// Node containing a (nullable) reference to the next node and an element. -pub struct StackNode<'a, Ctx: Context<'a>, A: MentionableBase<'a, Ctx>> { +pub struct StackNode<'a, Ctx: Context<'a>, A: MentionableBase<'a>> { /// Reference comes first due to being inlineable. pub rest: Stack<'a, Ctx, A>, /// Unlike the original implementation in Python, doesn't default to using Point. @@ -16,30 +18,38 @@ pub struct StackNode<'a, Ctx: Context<'a>, A: MentionableBase<'a, Ctx>> { /// Type representing a stack, an alias to a [Nullable] of a [StackNode]. pub type Stack<'a, Ctx, A> = Nullable<'a, Ctx, StackNode<'a, Ctx, A>>; -#[derive(Clone)] -pub struct StackNodeFactory { +pub struct StackNodeFactory { element_factory: F, + _ctx: PhantomData, } -impl StackNodeFactory { - fn new(factory: F) -> Self { - StackNodeFactory { - element_factory: factory, +impl Clone for StackNodeFactory { + fn clone(&self) -> Self { + Self { + element_factory: self.element_factory.clone(), + _ctx: PhantomData, } } } -impl<'a, Ctx: Context<'a>, A: MentionableBase<'a, Ctx>> Serializable for StackNode<'a, Ctx, A> { +impl StackNodeFactory { + fn new(factory: F) -> Self { + StackNodeFactory { + element_factory: factory, + _ctx: PhantomData, + } + } +} + +impl<'a, Ctx: Context<'a>, A: MentionableBase<'a>> Serializable for StackNode<'a, Ctx, A> { fn serialize(&self, serializer: &mut dyn Serializer) { self.rest.serialize(serializer); self.element.serialize(serializer); } } -impl<'a, Ctx: Context<'a>, A: MentionableBase<'a, Ctx>> MentionableBase<'a, Ctx> - for StackNode<'a, Ctx, A> -{ - type Fctr = StackNodeFactory; +impl<'a, Ctx: Context<'a>, A: MentionableBase<'a>> MentionableBase<'a> for StackNode<'a, Ctx, A> { + type Fctr = StackNodeFactory; fn factory(&self) -> Self::Fctr { StackNodeFactory::new(self.element.factory()) @@ -85,34 +95,34 @@ impl Display for StackParseError { impl Error for StackParseError {} -impl StackNodeFactory { - fn parse_point<'a, Ctx: Context<'a>, I: InCtx<'a, Ctx>>( +impl<'a, Ctx: Context<'a>, F> StackNodeFactory { + fn parse_point>( &self, inctx: I, - ) -> IParseResult<'a, Ctx, NullableFactory, I> + ) -> IParseResult<'a, NullableFactory, I> where - StackNodeFactory: Factory<'a, Ctx>, + StackNodeFactory: Factory<'a, Ctx>, { NullableFactory::new(self.clone()).ideserialize(inctx) } } -impl<'a, Ctx: Context<'a>, F: FactoryBase<'a, Ctx>> FactoryBase<'a, Ctx> for StackNodeFactory { +impl<'a, Ctx: Context<'a>, F: FactoryBase<'a>> FactoryBase<'a> for StackNodeFactory { type Mtbl = StackNode<'a, Ctx, F::Mtbl>; - type ParseError = StackParseError>; + type ParseError = StackParseError>; } -impl ParseMode for StackNodeFactory { +impl ParseMode for StackNodeFactory { type Mode = F::Mode; } impl<'a, Ctx: Context<'a>, F: FactoryModeParse<'a, Ctx>> FactoryModeParse<'a, Ctx> - for StackNodeFactory + for StackNodeFactory where F::Mtbl: MentionableTop<'a, Ctx>, { - fn mdeserialize>(&self, inctx: I) -> ModeResultM<'a, Ctx, Self, I> { + fn mdeserialize>(&self, inctx: I) -> ModeResultM<'a, Self, I> { let (rest, inctx) = self.parse_point(inctx)?; let selement = self .element_factory @@ -123,9 +133,9 @@ where fn mextend( &self, - mentionable: ExtensionSourceM<'a, Ctx, Self>, + mentionable: ExtensionSourceM<'a, Self>, tail: &[u8], - ) -> ExtensionResultM<'a, Ctx, Self> { + ) -> ExtensionResultM<'a, Self> { Self::xsbind( mentionable, |StackNode { rest, element }| (rest, element), @@ -141,7 +151,7 @@ where } impl<'a, Ctx: Context<'a>, F: Factory<'a, Ctx> + FixedSizeFactory<'a, Ctx>> - FixedSizeFactory<'a, Ctx> for StackNodeFactory + FixedSizeFactory<'a, Ctx> for StackNodeFactory where F::Mtbl: MentionableTop<'a, Ctx>, { @@ -151,7 +161,7 @@ where } impl<'a, Ctx: Context<'a>, F: Factory<'a, Ctx> + ConstSizeFactory<'a, Ctx>> - ConstSizeFactory<'a, Ctx> for StackNodeFactory + ConstSizeFactory<'a, Ctx> for StackNodeFactory where F::Mtbl: MentionableTop<'a, Ctx>, { @@ -168,9 +178,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: MentionableBase<'a, Ctx>>: - MentionableBase<'a, Ctx> -{ +pub trait ExtStack<'a, Ctx: Context<'a>, A: MentionableBase<'a>>: MentionableBase<'a> { /// Get an empty stack ([`Nullable::Null`]). fn empty(factory: A::Fctr) -> Self; /// Get the corresponding factory. @@ -183,7 +191,7 @@ pub trait ExtStack<'a, Ctx: Context<'a>, A: MentionableBase<'a, Ctx>>: /// Extention trait with helper methods for [Stack]s. pub trait ExtStackClone<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx> + Clone>: - MentionableBase<'a, Ctx> + MentionableBase<'a> { /// Collect all the elements into a [`Vec`]. fn vec(self) -> StackVecWrapped<'a, Ctx, A>; @@ -192,7 +200,7 @@ pub trait ExtStackClone<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx> + Clone>: impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx> + Mentionable<'a, Ctx>> ExtStack<'a, Ctx, A> for Stack<'a, Ctx, A> where - StackNode<'a, Ctx, A>: Mentionable<'a, Ctx, _Fctr = StackNodeFactory>, + StackNode<'a, Ctx, A>: Mentionable<'a, Ctx, _Fctr = StackNodeFactory>, { fn empty(factory: A::Fctr) -> Self { Nullable::Null(StackNodeFactory::new(factory.clone())) @@ -214,8 +222,8 @@ where impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx> + Clone> ExtStackClone<'a, Ctx, A> for Stack<'a, Ctx, A> where - StackNode<'a, Ctx, A>: Mentionable<'a, Ctx, _Fctr = StackNodeFactory>, - StackNodeFactory: FactoryParse<'a, Ctx>, + StackNode<'a, Ctx, A>: Mentionable<'a, Ctx, _Fctr = StackNodeFactory>, + StackNodeFactory: FactoryParse<'a, Ctx>, { fn vec(self) -> StackVecWrapped<'a, Ctx, A> { Ctx::T::iterate_mut((vec![], self), |(mut vec, stack)| match stack { diff --git a/src/rstd/collections/tree.rs b/src/rstd/collections/tree.rs index 4c7e10b..378829a 100644 --- a/src/rstd/collections/tree.rs +++ b/src/rstd/collections/tree.rs @@ -1,7 +1,7 @@ use crate::atomic::*; pub mod context; -use std::{error::Error, fmt::Display}; +use std::{error::Error, fmt::Display, marker::PhantomData}; use crate::{ flow::binary::*, @@ -57,18 +57,18 @@ impl Display for TreeParseError { impl Error for TreeParseError {} -pub struct Node<'a, Ctx: Context<'a>, A: MentionableBase<'a, Ctx>> { +pub struct Node<'a, Ctx: Context<'a>, A: MentionableBase<'a>> { l: Tree<'a, Ctx, A>, r: Tree<'a, Ctx, A>, key: A, } -pub struct Tree<'a, Ctx: Context<'a>, A: MentionableBase<'a, Ctx>> { +pub struct Tree<'a, Ctx: Context<'a>, A: MentionableBase<'a>> { node: Nullable<'a, Ctx, Node<'a, Ctx, A>>, height: u64, } -impl<'a, Ctx: Context<'a>, A: MentionableBase<'a, Ctx>> Tree<'a, Ctx, A> { +impl<'a, Ctx: Context<'a>, A: MentionableBase<'a>> Tree<'a, Ctx, A> { fn validate_height(&self) -> Result<(), HeightError> { match (&self.node, self.height) { (Nullable::NotNull(_), 0) => Err(HeightError::NodeHeight), @@ -79,13 +79,29 @@ impl<'a, Ctx: Context<'a>, A: MentionableBase<'a, Ctx>> Tree<'a, Ctx, A> { } } -#[derive(Clone)] -pub struct NodeFactory(F); +pub struct NodeFactory { + factory: F, + _ctx: PhantomData, +} -#[derive(Clone)] -pub struct TreeFactory(NullableFactory>); +impl Clone for NodeFactory { + fn clone(&self) -> Self { + Self { + factory: self.factory.clone(), + _ctx: PhantomData, + } + } +} -impl<'a, Ctx: Context<'a>, A: MentionableBase<'a, Ctx>> Serializable for Node<'a, Ctx, A> { +pub struct TreeFactory(NullableFactory>); + +impl Clone for TreeFactory { + fn clone(&self) -> Self { + Self(self.0.clone()) + } +} + +impl<'a, Ctx: Context<'a>, A: MentionableBase<'a>> Serializable for Node<'a, Ctx, A> { fn serialize(&self, serializer: &mut dyn Serializer) { self.l.serialize(serializer); self.r.serialize(serializer); @@ -93,20 +109,21 @@ impl<'a, Ctx: Context<'a>, A: MentionableBase<'a, Ctx>> Serializable for Node<'a } } -impl<'a, Ctx: Context<'a>, A: MentionableBase<'a, Ctx>> Serializable for Tree<'a, Ctx, A> { +impl<'a, Ctx: Context<'a>, A: MentionableBase<'a>> Serializable for Tree<'a, Ctx, A> { fn serialize(&self, serializer: &mut dyn Serializer) { self.height.serialize(serializer); self.node.serialize(serializer); } } -impl<'a, Ctx: Context<'a>, A: MentionableBase<'a, Ctx>> MentionableBase<'a, Ctx> - for Node<'a, Ctx, A> -{ - type Fctr = NodeFactory; +impl<'a, Ctx: Context<'a>, A: MentionableBase<'a>> MentionableBase<'a> for Node<'a, Ctx, A> { + type Fctr = NodeFactory; fn factory(&self) -> Self::Fctr { - NodeFactory(self.key.factory()) + NodeFactory { + factory: self.key.factory(), + _ctx: PhantomData, + } } } @@ -118,10 +135,8 @@ impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> MentionableTop<'a, Ctx> for } } -impl<'a, Ctx: Context<'a>, A: MentionableBase<'a, Ctx>> MentionableBase<'a, Ctx> - for Tree<'a, Ctx, A> -{ - type Fctr = TreeFactory; +impl<'a, Ctx: Context<'a>, A: MentionableBase<'a>> MentionableBase<'a> for Tree<'a, Ctx, A> { + type Fctr = TreeFactory; fn factory(&self) -> Self::Fctr { TreeFactory(self.node.factory()) @@ -134,57 +149,62 @@ impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> MentionableTop<'a, Ctx> for } } -impl<'a, Ctx: Context<'a>, F: FactoryBase<'a, Ctx>> FactoryBase<'a, Ctx> for NodeFactory { +impl<'a, Ctx: Context<'a>, F: FactoryBase<'a>> FactoryBase<'a> for NodeFactory { type Mtbl = Node<'a, Ctx, F::Mtbl>; type ParseError = TreeParseError; } -impl ParseMode for NodeFactory { +impl ParseMode for NodeFactory { type Mode = F::Mode; } impl<'a, Ctx: Context<'a>, F: FactoryModeParse<'a, Ctx>> FactoryModeParse<'a, Ctx> - for NodeFactory + for NodeFactory { - fn mdeserialize>(&self, inctx: I) -> ModeResultM<'a, Ctx, Self, I> { + fn mdeserialize>(&self, inctx: I) -> ModeResultM<'a, Self, I> { let tree_factory = TreeFactory(NullableFactory::new(self.clone())); let (l, inctx) = tree_factory.ideserialize(inctx)?; let (r, inctx) = tree_factory.ideserialize(inctx)?; - let skey = self.0.mdeserialize(inctx).map_err(TreeParseError::Key)?; + let skey = self + .factory + .mdeserialize(inctx) + .map_err(TreeParseError::Key)?; Ok(Self::map(skey, |key| Node { l, r, key })) } fn mextend( &self, - mentionable: ExtensionSourceM<'a, Ctx, Self>, + mentionable: ExtensionSourceM<'a, Self>, tail: &[u8], - ) -> ExtensionResultM<'a, Ctx, Self> { + ) -> ExtensionResultM<'a, Self> { Self::xsbind( mentionable, |Node { l, r, key }| ((l, r), key), - |key| Self::xmap_err(self.0.mextend(key, tail), TreeParseError::Key), + |key| Self::xmap_err(self.factory.mextend(key, tail), TreeParseError::Key), |(l, r), key| Ok(Node { l, r, key }), ) } } -impl<'a, Ctx: Context<'a>, F: FactoryBase<'a, Ctx>> FactoryBase<'a, Ctx> for TreeFactory { +impl<'a, Ctx: Context<'a>, F: FactoryBase<'a>> FactoryBase<'a> for TreeFactory { type Mtbl = Tree<'a, Ctx, F::Mtbl>; type ParseError = TreeParseError; } -impl ImplMode for TreeFactory { +impl ImplMode for TreeFactory { type Mode = InliningMode; } -impl<'a, Ctx: Context<'a>, F: FactoryParse<'a, Ctx>> CInliningFactory<'a, Ctx> for TreeFactory { +impl<'a, Ctx: Context<'a>, F: FactoryParse<'a, Ctx>> CInliningFactory<'a, Ctx> + for TreeFactory +{ fn cextension_error(&self, tail: &[u8]) -> Self::ParseError { u64::a_extension_error(tail).into() } - fn cideserialize>(&self, inctx: I) -> IParseResult<'a, Ctx, Self, I> { + fn cideserialize>(&self, inctx: I) -> IParseResult<'a, Self, I> { let (node, inctx) = self.0.ideserialize(inctx)?; let (height, inctx) = u64::a_ideserialize(inctx)?; let tree = Tree { node, height }; @@ -193,7 +213,7 @@ impl<'a, Ctx: Context<'a>, F: FactoryParse<'a, Ctx>> CInliningFactory<'a, Ctx> f } } -impl<'a, Ctx: Context<'a>, A: MentionableBase<'a, Ctx> + Clone> Clone for Node<'a, Ctx, A> { +impl<'a, Ctx: Context<'a>, A: MentionableBase<'a> + Clone> Clone for Node<'a, Ctx, A> { fn clone(&self) -> Self { Self { l: self.l.clone(), @@ -203,7 +223,7 @@ impl<'a, Ctx: Context<'a>, A: MentionableBase<'a, Ctx> + Clone> Clone for Node<' } } -impl<'a, Ctx: Context<'a>, A: MentionableBase<'a, Ctx> + Clone> Clone for Tree<'a, Ctx, A> { +impl<'a, Ctx: Context<'a>, A: MentionableBase<'a> + Clone> Clone for Tree<'a, Ctx, A> { fn clone(&self) -> Self { Self { node: self.node.clone(), diff --git a/src/rstd/collections/tree/context.rs b/src/rstd/collections/tree/context.rs index ebd330a..c2a5b6b 100644 --- a/src/rstd/collections/tree/context.rs +++ b/src/rstd/collections/tree/context.rs @@ -38,12 +38,12 @@ impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>, E: 'a> } } -type TreeParseError2<'a, Ctx, A> = TreeParseError>; +type TreeParseError2<'a, A> = TreeParseError>; -impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>, E: 'a> From> +impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>, E: 'a> From> for TreeContextError<'a, Ctx, A, E> { - fn from(value: TreeParseError2<'a, Ctx, A>) -> Self { + fn from(value: TreeParseError2<'a, A>) -> Self { ResolutionError::Parse(value).into() } } @@ -56,8 +56,7 @@ impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>, E: 'a> From } } -pub type TreeContext2<'a, Ctx, A, C, E> = - TreeContext<(Arc, Fctr<'a, Ctx, A>), (&'a (), Ctx, A, E)>; +pub type TreeContext2<'a, Ctx, A, C, E> = TreeContext<(Arc, Fctr<'a, A>), (&'a (), Ctx, A, E)>; impl< 'a, @@ -133,7 +132,10 @@ impl< { fn empty(&self) -> Self::Tree { Tree { - node: Nullable::Null(NodeFactory(self.0 .1.clone())), + node: Nullable::Null(NodeFactory { + factory: self.0 .1.clone(), + _ctx: PhantomData, + }), height: 0, } } diff --git a/src/rstd/inject.rs b/src/rstd/inject.rs index 80816aa..8a5014d 100644 --- a/src/rstd/inject.rs +++ b/src/rstd/inject.rs @@ -6,10 +6,7 @@ use crate::rstd::{singular::*, *}; pub trait Inject<'a, Ctx: Context<'a>>: 'a + Send + Sync + Sized { fn inject(&self, fa: Wrapped<'a, Ctx, A>) -> Wrapped<'a, Ctx, A>; - fn inject_mentionable>( - self: Arc, - a: &A, - ) -> ParseResultA<'a, Ctx, A> { + fn inject_mentionable>(self: Arc, a: &A) -> ParseResultA<'a, A> { let factory = a.factory(); let inject = self; let resolver = SingularResolver::from_mentionable(a).into_rc(); diff --git a/src/rstd/inlining.rs b/src/rstd/inlining.rs index 69ca5bc..79c7d6e 100644 --- a/src/rstd/inlining.rs +++ b/src/rstd/inlining.rs @@ -122,15 +122,15 @@ impl From

for CheckedParseError

{ } } -pub type CheckedParseFailure<'a, Ctx, F> = CheckedParseError>; +pub type CheckedParseFailure<'a, F> = CheckedParseError>; /// Returned by [`CheckedParse::deserialize_checked`]. -pub type CheckedParseResult<'a, Ctx, F> = Result, CheckedParseFailure<'a, Ctx, F>>; +pub type CheckedParseResult<'a, F> = Result, CheckedParseFailure<'a, F>>; /// Extension trait for factories that ensures fixed size read. pub trait CheckedParse<'a, Ctx: Context<'a>>: FixedSizeFactory<'a, Ctx> { /// Verify proper read length using [`Deserializer::tell`]. - fn deserialize_checked(&self, inctx: impl InCtx<'a, Ctx>) -> CheckedParseResult<'a, Ctx, Self> { + fn deserialize_checked(&self, inctx: impl InCtx<'a, Ctx>) -> CheckedParseResult<'a, Self> { let expected_size = self.size(); let start = inctx.itell(); let (result, inctx) = self.ideserialize(inctx)?; diff --git a/src/rstd/inlining/static_pair.rs b/src/rstd/inlining/static_pair.rs index 6b8ebf3..0ed4f6b 100644 --- a/src/rstd/inlining/static_pair.rs +++ b/src/rstd/inlining/static_pair.rs @@ -29,19 +29,19 @@ pub trait StaticPairSerializable { /// at the cost of having to specify two extra fields. /// /// Note: [`StaticPair::FA`] requires [`InliningFactory`] be implemented. -pub trait StaticPair<'a, Ctx: Context<'a>>: +pub trait StaticPair<'a>: 'a + Send + Sync + StaticPairSerializable + Sized { /// [Factory] data. May, depending on the usecase, include factory (factories) on the element(s). type FactoryData: 'a + Send + Sync + Clone; /// First element's type. Must equal [`StaticPairSerializable::SA`]. - type A: MentionableBase<'a, Ctx, Fctr = Self::FA>; + type A: MentionableBase<'a, Fctr = Self::FA>; /// Second element's type. Must equal [`StaticPairSerializable::SB`]. - type B: MentionableBase<'a, Ctx, Fctr = Self::FB>; + type B: MentionableBase<'a, Fctr = Self::FB>; /// First element's factory. - type FA: FactoryBase<'a, Ctx, Mtbl = Self::A> + ParseMode; + type FA: FactoryBase<'a, Mtbl = Self::A> + ParseMode; /// Second element's factory. - type FB: FactoryBase<'a, Ctx, Mtbl = Self::B> + ParseMode; + type FB: FactoryBase<'a, Mtbl = Self::B> + ParseMode; /// See [`FactoryBase::ParseError`]. type ParseError: 'a + Send + Error; @@ -56,12 +56,12 @@ pub trait StaticPair<'a, Ctx: Context<'a>>: /// Regularise the error returned while parsing the first element. fn from_error_a( factory_data: &Self::FactoryData, - error: ParseError<'a, Ctx, Self::FA>, + error: ParseError<'a, Self::FA>, ) -> Self::ParseError; /// Regularise the error returned while parsing the second element. fn from_error_b( factory_data: &Self::FactoryData, - error: ParseError<'a, Ctx, Self::FB>, + error: ParseError<'a, Self::FB>, ) -> Self::ParseError; /// Derive factory data from the object data. fn factory_data(&self) -> Self::FactoryData; @@ -94,7 +94,7 @@ impl Deref for StaticPairObject { } /// Generic implementation of a [Factory] for [StaticPair]s. -pub struct StaticPairFactory<'a, Ctx: Context<'a>, SP: StaticPair<'a, Ctx>> { +pub struct StaticPairFactory<'a, SP: StaticPair<'a>> { factory_data: SP::FactoryData, } @@ -112,10 +112,8 @@ impl Serializable for StaticPairObject { } } -impl<'a, Ctx: Context<'a>, SP: StaticPair<'a, Ctx>> MentionableBase<'a, Ctx> - for StaticPairObject -{ - type Fctr = StaticPairFactory<'a, Ctx, SP>; +impl<'a, SP: StaticPair<'a>> MentionableBase<'a> for StaticPairObject { + type Fctr = StaticPairFactory<'a, SP>; fn factory(&self) -> Self::Fctr { StaticPairFactory { @@ -129,7 +127,7 @@ impl StaticPairObject { pair: &SP, points: &mut impl PointsVisitor<'a, Ctx>, ) where - SP: StaticPair<'a, Ctx>, + SP: StaticPair<'a>, SP::A: Mentionable<'a, Ctx>, SP::B: Mentionable<'a, Ctx>, { @@ -139,7 +137,7 @@ impl StaticPairObject { } } -impl<'a, Ctx: Context<'a>, SP: StaticPair<'a, Ctx>> MentionableTop<'a, Ctx> for StaticPairObject +impl<'a, Ctx: Context<'a>, SP: StaticPair<'a>> MentionableTop<'a, Ctx> for StaticPairObject where SP::A: Mentionable<'a, Ctx>, SP::B: Mentionable<'a, Ctx>, @@ -149,7 +147,7 @@ where } } -impl<'a, Ctx: Context<'a>, SP: StaticPair<'a, Ctx>> Clone for StaticPairFactory<'a, Ctx, SP> { +impl<'a, SP: StaticPair<'a>> Clone for StaticPairFactory<'a, SP> { fn clone(&self) -> Self { Self { factory_data: self.factory_data.clone(), @@ -157,27 +155,25 @@ impl<'a, Ctx: Context<'a>, SP: StaticPair<'a, Ctx>> Clone for StaticPairFactory< } } -impl<'a, Ctx: Context<'a>, SP: StaticPair<'a, Ctx>> FactoryBase<'a, Ctx> - for StaticPairFactory<'a, Ctx, SP> -{ +impl<'a, SP: StaticPair<'a>> FactoryBase<'a> for StaticPairFactory<'a, SP> { type Mtbl = StaticPairObject; type ParseError = SP::ParseError; } -impl<'a, Ctx: Context<'a>, SP: StaticPair<'a, Ctx>> ParseMode for StaticPairFactory<'a, Ctx, SP> { +impl<'a, SP: StaticPair<'a>> ParseMode for StaticPairFactory<'a, SP> { type Mode = ::Mode; } -impl<'a, Ctx: Context<'a>, SP: StaticPair<'a, Ctx>> StaticPairFactory<'a, Ctx, SP> -where - SP::FA: InliningFactory<'a, Ctx>, - SP::FB: FactoryModeParse<'a, Ctx>, -{ - pub fn mdeserialize_sp>( +impl<'a, SP: StaticPair<'a>> StaticPairFactory<'a, SP> { + pub fn mdeserialize_sp, I: InCtx<'a, Ctx>>( factory_data: &SP::FactoryData, inctx: I, - ) -> ModeResultP { + ) -> ModeResultP + where + SP::FA: InliningFactory<'a, Ctx>, + SP::FB: FactoryModeParse<'a, Ctx>, + { let (fa, fb) = SP::factories(factory_data); let (a, inctx) = fa .ideserialize(inctx) @@ -189,11 +185,15 @@ where ) } - pub fn mextend_sp( + pub fn mextend_sp>( factory_data: &SP::FactoryData, mentionable: ExtensionSourceP, tail: &[u8], - ) -> ExtensionResultP { + ) -> ExtensionResultP + where + SP::FA: InliningFactory<'a, Ctx>, + SP::FB: FactoryModeParse<'a, Ctx>, + { let (_, fb) = SP::factories(factory_data); // annotated to help rust-analyzer Self::xsbind::( @@ -205,13 +205,13 @@ where } } -impl<'a, Ctx: Context<'a>, SP: StaticPair<'a, Ctx>> FactoryModeParse<'a, Ctx> - for StaticPairFactory<'a, Ctx, SP> +impl<'a, Ctx: Context<'a>, SP: StaticPair<'a>> FactoryModeParse<'a, Ctx> + for StaticPairFactory<'a, SP> where SP::FA: InliningFactory<'a, Ctx>, SP::FB: FactoryModeParse<'a, Ctx>, { - fn mdeserialize>(&self, inctx: I) -> ModeResultM<'a, Ctx, Self, I> { + fn mdeserialize>(&self, inctx: I) -> ModeResultM<'a, Self, I> { Ok(Self::map( Self::mdeserialize_sp(&self.factory_data, inctx)?, |pair| StaticPairObject { pair }, @@ -220,9 +220,9 @@ where fn mextend( &self, - mentionable: ExtensionSourceM<'a, Ctx, Self>, + mentionable: ExtensionSourceM<'a, Self>, tail: &[u8], - ) -> ExtensionResultM<'a, Ctx, Self> { + ) -> ExtensionResultM<'a, Self> { Self::xbind( Self::mextend_sp( &self.factory_data, @@ -234,8 +234,8 @@ where } } -impl<'a, Ctx: Context<'a>, SP: StaticPair<'a, Ctx>> FixedSizeFactory<'a, Ctx> - for StaticPairFactory<'a, Ctx, SP> +impl<'a, Ctx: Context<'a>, SP: StaticPair<'a>> FixedSizeFactory<'a, Ctx> + for StaticPairFactory<'a, SP> where SP::FA: FixedSizeFactory<'a, Ctx>, SP::FB: FixedSizeFactory<'a, Ctx> + FactoryModeParse<'a, Ctx>, @@ -246,8 +246,8 @@ where } } -impl<'a, Ctx: Context<'a>, SP: StaticPair<'a, Ctx>> ConstSizeFactory<'a, Ctx> - for StaticPairFactory<'a, Ctx, SP> +impl<'a, Ctx: Context<'a>, SP: StaticPair<'a>> ConstSizeFactory<'a, Ctx> + for StaticPairFactory<'a, SP> where SP::FA: ConstSizeFactory<'a, Ctx>, SP::FB: ConstSizeFactory<'a, Ctx> + FactoryModeParse<'a, Ctx>, diff --git a/src/rstd/nullable.rs b/src/rstd/nullable.rs index 9010d4d..185f21e 100644 --- a/src/rstd/nullable.rs +++ b/src/rstd/nullable.rs @@ -1,5 +1,7 @@ //! This module introduces [`Option`]-like concepts into RADN typesystem using [`Nullable`]. +use std::marker::PhantomData; + use crate::func::context::*; use crate::mode::*; use crate::rcore::*; @@ -7,20 +9,29 @@ use crate::rcore::*; use super::{inlining::*, point::*, *}; /// Nullable reference type. Made for use as a linking element in data structures. -pub enum Nullable<'a, Ctx: Context<'a>, A: MentionableBase<'a, Ctx>> { +pub enum Nullable<'a, Ctx: Context<'a>, A: MentionableBase<'a>> { /// Unlike original Python implementation, stores the factory only in the null case. Null(A::Fctr), NotNull(Point<'a, Ctx, A>), } /// Nullable reference factory. -#[derive(Clone)] -pub struct NullableFactory { +pub struct NullableFactory { /// Factory of the referenced object. factory: F, + _ctx: PhantomData, } -impl<'a, Ctx: Context<'a>, A: MentionableBase<'a, Ctx>> Serializable for Nullable<'a, Ctx, A> { +impl Clone for NullableFactory { + fn clone(&self) -> Self { + Self { + factory: self.factory.clone(), + _ctx: PhantomData, + } + } +} + +impl<'a, Ctx: Context<'a>, A: MentionableBase<'a>> Serializable for Nullable<'a, Ctx, A> { fn serialize(&self, serializer: &mut dyn Serializer) { serializer.write(match self { Self::Null(_) => &HASH_ZEROS, @@ -29,19 +40,13 @@ impl<'a, Ctx: Context<'a>, A: MentionableBase<'a, Ctx>> Serializable for Nullabl } } -impl<'a, Ctx: Context<'a>, A: MentionableBase<'a, Ctx>> MentionableBase<'a, Ctx> - for Nullable<'a, Ctx, A> -{ - type Fctr = NullableFactory; +impl<'a, Ctx: Context<'a>, A: MentionableBase<'a>> MentionableBase<'a> for Nullable<'a, Ctx, A> { + type Fctr = NullableFactory; fn factory(&self) -> Self::Fctr { match self { - Self::Null(factory) => NullableFactory { - factory: factory.clone(), - }, - Self::NotNull(point) => NullableFactory { - factory: point.origin.factory(), - }, + Self::Null(factory) => NullableFactory::new(factory.clone()), + Self::NotNull(point) => NullableFactory::new(point.origin.factory()), } } } @@ -57,13 +62,13 @@ impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> MentionableTop<'a, Ctx> } } -impl<'a, Ctx: Context<'a>, F: FactoryBase<'a, Ctx>> FactoryBase<'a, Ctx> for NullableFactory { +impl<'a, Ctx: Context<'a>, F: FactoryBase<'a>> FactoryBase<'a> for NullableFactory { type Mtbl = Nullable<'a, Ctx, F::Mtbl>; type ParseError = PointParseError; } -impl ImplMode for NullableFactory { +impl ImplMode for NullableFactory { type Mode = InliningMode; } @@ -72,7 +77,7 @@ impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> Nullable<'a, Ctx, Nullable<' pub fn join(&self) -> Resolution<'a, Ctx, Nullable<'a, Ctx, A>> { match self { Self::Null(nullable_factory) => { - let NullableFactory { factory } = nullable_factory; + let NullableFactory { factory, .. } = nullable_factory; Ctx::pure(Ok(Arc::new(Nullable::Null(factory.clone())))) } Self::NotNull(point) => point.resolve(), @@ -93,7 +98,7 @@ impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> Nullable<'a, Ctx, A> { } } -impl<'a, Ctx: Context<'a>, A: MentionableBase<'a, Ctx>> Nullable<'a, Ctx, A> { +impl<'a, Ctx: Context<'a>, A: MentionableBase<'a>> Nullable<'a, Ctx, A> { pub fn is_null(&self) -> bool { match self { Nullable::Null(_) => true, @@ -102,13 +107,16 @@ impl<'a, Ctx: Context<'a>, A: MentionableBase<'a, Ctx>> Nullable<'a, Ctx, A> { } } -impl NullableFactory { +impl NullableFactory { pub fn new(factory: F) -> Self { - Self { factory } + Self { + factory, + _ctx: PhantomData, + } } } -impl<'a, Ctx: Context<'a>, A: MentionableBase<'a, Ctx>> Clone for Nullable<'a, Ctx, A> { +impl<'a, Ctx: Context<'a>, A: MentionableBase<'a>> Clone for Nullable<'a, Ctx, A> { fn clone(&self) -> Self { match self { Self::Null(factory) => Self::Null(factory.clone()), @@ -117,14 +125,14 @@ impl<'a, Ctx: Context<'a>, A: MentionableBase<'a, Ctx>> Clone for Nullable<'a, C } } -impl<'a, Ctx: Context<'a>, F: FactoryBase<'a, Ctx>> CInliningFactory<'a, Ctx> - for NullableFactory +impl<'a, Ctx: Context<'a>, F: FactoryBase<'a>> CInliningFactory<'a, Ctx> + for NullableFactory { fn cextension_error(&self, tail: &[u8]) -> Self::ParseError { PointParseError::WrongLength(HASH_SIZE + tail.len()) } - fn cideserialize>(&self, inctx: I) -> IParseResult<'a, Ctx, Self, I> { + fn cideserialize>(&self, inctx: I) -> IParseResult<'a, Self, I> { let factory = self.factory.clone(); let (address, inctx) = inctx.icnext_address(PointParseError::from_ref)?; Ok(( @@ -138,7 +146,7 @@ impl<'a, Ctx: Context<'a>, F: FactoryBase<'a, Ctx>> CInliningFactory<'a, Ctx> } } -impl AlwaysConstSize for NullableFactory { +impl AlwaysConstSize for NullableFactory { const _SIZE: usize = HASH_SIZE; } diff --git a/src/rstd/point.rs b/src/rstd/point.rs index e492432..25705cd 100644 --- a/src/rstd/point.rs +++ b/src/rstd/point.rs @@ -1,25 +1,31 @@ //! Module responsible for making [Point]s [Mentionable]. +use std::marker::PhantomData; use std::{error::Error, fmt::Display}; use crate::mode::*; use crate::rcore::*; use crate::rstd::inlining::*; -impl<'a, Ctx: Context<'a>, A: MentionableBase<'a, Ctx>> Serializable for Point<'a, Ctx, A> { +impl<'a, Ctx: Context<'a>, A: MentionableBase<'a>> Serializable for Point<'a, Ctx, A> { fn serialize(&self, serializer: &mut dyn Serializer) { serializer.write(&self.point) } } -impl<'a, Ctx: Context<'a>, A: MentionableBase<'a, Ctx>> MentionableBase<'a, Ctx> - for Point<'a, Ctx, A> -{ - type Fctr = PointFactory; +impl<'a, Ctx: Context<'a>, A: MentionableBase<'a>> MentionableBase<'a> for Point<'a, Ctx, A> { + type Fctr = PointFactory; fn factory(&self) -> Self::Fctr { - PointFactory { - factory: self.origin.factory(), + PointFactory::new(self.origin.factory()) + } +} + +impl PointFactory { + fn new(factory: F) -> Self { + Self { + factory, + _ctx: PhantomData, } } } @@ -34,12 +40,18 @@ impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> MentionableTop<'a, Ctx> for } } -#[derive(Clone)] -pub struct PointFactory { +pub struct PointFactory { factory: F, + _ctx: PhantomData, } -impl PointFactory { +impl Clone for PointFactory { + fn clone(&self) -> Self { + Self::new(self.factory.clone()) + } +} + +impl PointFactory { pub fn inner(&self) -> F { self.factory.clone() } @@ -68,32 +80,32 @@ impl From<&[u8]> for PointParseError { } } -impl<'a, Ctx: Context<'a>, A: MentionableBase<'a, Ctx>> AsRef<[u8]> for Point<'a, Ctx, A> { +impl<'a, Ctx: Context<'a>, A: MentionableBase<'a>> AsRef<[u8]> for Point<'a, Ctx, A> { fn as_ref(&self) -> &[u8] { &self.point } } -impl<'a, Ctx: Context<'a>, F: FactoryBase<'a, Ctx>> FactoryBase<'a, Ctx> for PointFactory { +impl<'a, Ctx: Context<'a>, F: FactoryBase<'a>> FactoryBase<'a> for PointFactory { type Mtbl = Point<'a, Ctx, F::Mtbl>; type ParseError = PointParseError; } -impl ImplMode for PointFactory { +impl ImplMode for PointFactory { type Mode = InliningMode; } -impl<'a, Ctx: Context<'a>, F: FactoryBase<'a, Ctx>> CInliningFactory<'a, Ctx> for PointFactory { +impl<'a, Ctx: Context<'a>, F: FactoryBase<'a>> CInliningFactory<'a, Ctx> for PointFactory { fn cextension_error(&self, tail: &[u8]) -> Self::ParseError { PointParseError::WrongLength(HASH_SIZE + tail.len()) } - fn cideserialize>(&self, inctx: I) -> IParseResult<'a, Ctx, Self, I> { + fn cideserialize>(&self, inctx: I) -> IParseResult<'a, Self, I> { inctx.icnext_point(self.inner(), PointParseError::from_ref) } } -impl AlwaysConstSize for PointFactory { +impl AlwaysConstSize for PointFactory { const _SIZE: usize = HASH_SIZE; } diff --git a/src/rstd/tracing/traceable.rs b/src/rstd/tracing/traceable.rs index 7befc9f..464df0c 100644 --- a/src/rstd/tracing/traceable.rs +++ b/src/rstd/tracing/traceable.rs @@ -19,7 +19,7 @@ pub trait Traceable<'a, Ctx: Context<'a, _Tm = TracedInstance>>: /// /// [^extra]: applying [`Traceable::trace`] multiple times /// might affect the trace in undesireable ways - fn trace(&self) -> ParseResultA<'a, Ctx, Self> { + fn trace(&self) -> ParseResultA<'a, Self> { Arc::new(TracedInject).inject_mentionable(self) } } diff --git a/src/rstd/typeless.rs b/src/rstd/typeless.rs index 81aca8b..dd5b7b5 100644 --- a/src/rstd/typeless.rs +++ b/src/rstd/typeless.rs @@ -51,7 +51,7 @@ impl<'a, Ctx: Context<'a>> Serializable for TypelessMentionable<'a, Ctx> { } } -impl<'a, Ctx: Context<'a>> MentionableBase<'a, Ctx> for TypelessMentionable<'a, Ctx> { +impl<'a, Ctx: Context<'a>> MentionableBase<'a> for TypelessMentionable<'a, Ctx> { type Fctr = TypelessFactory<'a, Ctx>; fn factory(&self) -> Self::Fctr { @@ -92,7 +92,7 @@ impl<'a> Display for TypelessError<'a> { impl<'a> Error for TypelessError<'a> {} -impl<'a, Ctx: Context<'a>> FactoryBase<'a, Ctx> for TypelessFactory<'a, Ctx> { +impl<'a, Ctx: Context<'a>> FactoryBase<'a> for TypelessFactory<'a, Ctx> { type Mtbl = TypelessMentionable<'a, Ctx>; type ParseError = TypelessError<'a>; @@ -103,11 +103,11 @@ impl<'a, Ctx: Context<'a>> ImplMode for TypelessFactory<'a, Ctx> { } impl<'a, Ctx: Context<'a>> CRegularFactory<'a, Ctx> for TypelessFactory<'a, Ctx> { - fn crdeserialize(&self, inctx: impl InCtx<'a, Ctx>) -> ParseResult<'a, Ctx, Self> { + fn crdeserialize(&self, inctx: impl InCtx<'a, Ctx>) -> ParseResult<'a, Self> { self.t_deserialize.de(inctx.demote()).map_err(TypelessError) } - fn crextend(&self, mentionable: Self::Mtbl, tail: &[u8]) -> ParseResult<'a, Ctx, Self> { + fn crextend(&self, mentionable: Self::Mtbl, tail: &[u8]) -> ParseResult<'a, Self> { self.t_extend.xt(mentionable, tail) } } diff --git a/src/rstd/wrapped_origin.rs b/src/rstd/wrapped_origin.rs index 250c534..13f1062 100644 --- a/src/rstd/wrapped_origin.rs +++ b/src/rstd/wrapped_origin.rs @@ -22,7 +22,7 @@ pub trait MappableOrigin<'a, Ctx: Context<'a>>: Origin<'a, Ctx> { + Send + Sync + Clone - + Fn(ParseError<'a, Ctx, OFctr<'a, Ctx, Self>>) -> ParseError<'a, Ctx, B::Fctr>, + + Fn(ParseError<'a, OFctr<'a, Ctx, Self>>) -> ParseError<'a, B::Fctr>, map_factory: impl 'a + FnOnce(OFctr<'a, Ctx, Self>) -> B::Fctr, ) -> Arc> where @@ -50,7 +50,7 @@ impl<'a, Ctx: Context<'a>, O: ?Sized + Origin<'a, Ctx>> MappableOrigin<'a, Ctx> fn map_resolve<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>, B: Mentionable<'a, Ctx>>( resolve: impl 'a + Send + Fn() -> Resolution<'a, Ctx, A>, map_ok: impl 'a + Send + Fn(Arc) -> B, - map_err: impl 'a + Send + Fn(ParseError<'a, Ctx, A::Fctr>) -> ParseError<'a, Ctx, B::Fctr>, + map_err: impl 'a + Send + Fn(ParseError<'a, A::Fctr>) -> ParseError<'a, B::Fctr>, ) -> Resolution<'a, Ctx, B> { Ctx::fmap(resolve(), move |resolved| match resolved { Ok(mentionable) => Ok(Arc::new(map_ok(mentionable))), @@ -67,7 +67,7 @@ struct WrappedOrigin<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> { impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> Origin<'a, Ctx> for WrappedOrigin<'a, Ctx, A> { type Mtbl = A; - fn factory(&self) -> Fctr<'a, Ctx, Self::Mtbl> { + fn factory(&self) -> Fctr<'a, Self::Mtbl> { self.w_factory.clone() } diff --git a/src/testing/counted.rs b/src/testing/counted.rs index 2f3fb56..87a5d7b 100644 --- a/src/testing/counted.rs +++ b/src/testing/counted.rs @@ -70,7 +70,7 @@ impl<'a> Inject<'a, TestContextCounted> for CountedInject { } pub trait Delayable<'a>: Mentionable<'a, TestContextCounted> + Sized { - fn delay(&self) -> ParseResultA<'a, TestContextCounted, Self> { + fn delay(&self) -> ParseResultA<'a, Self> { Arc::new(CountedInject).inject_mentionable(self) } }