remove Ctx from bases
Some checks failed
buildbot/cargo fmt (1.72) Build done.
buildbot/cargo clippy (1.72) Build done.
buildbot/cargo doc (1.72) Build done.
buildbot/cargo test (1.65) Build done.
buildbot/cargo clippy (1.65) Build done.

This commit is contained in:
AF 2023-08-31 23:07:12 +00:00
parent c11990d020
commit 3c095f0fb5
27 changed files with 302 additions and 271 deletions

View File

@ -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> = <A as MentionableBase<'a, Ctx>>::Fctr;
pub type Fctr<'a, A> = <A as MentionableBase<'a>>::Fctr;
/// Shorthand for the type of values returned by [`FactoryParse::deserialize`].
pub type ParseResult<'a, Ctx, F> = Result<Mtbl<'a, Ctx, F>, ParseError<'a, Ctx, F>>;
pub type ParseResult<'a, F> = Result<Mtbl<'a, F>, ParseError<'a, F>>;
/// [`ParseResult`] associated with a [`Mentionable`] (instead of a [`Factory`]).
pub type ParseResultA<'a, Ctx, A> = Result<A, ParseErrorA<'a, Ctx, A>>;
pub type ParseResultA<'a, A> = Result<A, ParseErrorA<'a, A>>;
/// [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> = <F as FactoryBase<'a, Ctx>>::Mtbl;
pub type Mtbl<'a, F> = <F as FactoryBase<'a>>::Mtbl;
/// [`FactoryBase::ParseError`]. Mostly useful for `type` definitions.
pub type ParseError<'a, Ctx, F> = <F as FactoryBase<'a, Ctx>>::ParseError;
pub type ParseError<'a, F> = <F as FactoryBase<'a>>::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<dyn Resolver<'a, Ctx>>,
) -> ParseResult<'a, Ctx, Self>;
) -> ParseResult<'a, Self>;
}

View File

@ -44,7 +44,7 @@ pub(super) trait InliningAddresses<E>: 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<dyn Resolver<'a, Ctx>>,
@ -62,7 +62,7 @@ fn _parse_slice<'a, Ctx: Context<'a>, F: FactoryParse<'a, Ctx>>(
factory: &F,
slice: &[u8],
resolver: &Arc<dyn Resolver<'a, Ctx>>,
) -> 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<dyn Resolver<'a, Ctx>>,
) -> ParseResult<'a, Ctx, Self> {
) -> ParseResult<'a, Self> {
_parse_slice::<Ctx, _>(self, slice, resolver)
}
}

View File

@ -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>;

View File

@ -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,

View File

@ -6,7 +6,7 @@ pub trait InCtx<'a, Ctx: Context<'a>>: Stream {
fn icnext_address<E>(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,

View File

@ -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<Mode = InliningMode>
FactoryBase<'a> + ImplMode<Mode = InliningMode>
{
/// Concrete implementation of [`InliningFactory::extension_error`].
fn cextension_error(&self, tail: &[u8]) -> Self::ParseError;
/// Concrete implementation of [`InliningFactory::ideserialize`].
fn cideserialize<I: InCtx<'a, Ctx>>(&self, inctx: I) -> IParseResult<'a, Ctx, Self, I>;
fn cideserialize<I: InCtx<'a, Ctx>>(&self, inctx: I) -> IParseResult<'a, Self, I>;
}
/// Factory preserving the parser on success.
pub trait InliningFactory<'a, Ctx: Context<'a>>:
FactoryBase<'a, Ctx> + ParseMode<Mode = InliningMode>
FactoryBase<'a> + ParseMode<Mode = InliningMode>
{
/// 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<I: InCtx<'a, Ctx>>(&self, inctx: I) -> IParseResult<'a, Ctx, Self, I>;
fn ideserialize<I: InCtx<'a, Ctx>>(&self, inctx: I) -> IParseResult<'a, Self, I>;
}
impl<'a, Ctx: Context<'a>, F: FactoryModeParse<'a, Ctx> + ParseMode<Mode = InliningMode>>
@ -33,7 +33,7 @@ impl<'a, Ctx: Context<'a>, F: FactoryModeParse<'a, Ctx> + ParseMode<Mode = Inlin
self.mextend((), tail)
}
fn ideserialize<I: InCtx<'a, Ctx>>(&self, inctx: I) -> IParseResult<'a, Ctx, Self, I> {
fn ideserialize<I: InCtx<'a, Ctx>>(&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<I: InCtx<'a, Ctx>>(f: &Self::F, inctx: I) -> ModeResultM<'a, Ctx, F, I> {
fn pmdeserialize<I: InCtx<'a, Ctx>>(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)
}
}

View File

@ -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<F, Mtbl<'a, Ctx, F>, ParseError<'a, Ctx, F>, I>;
pub type ModeResultM<'a, F, I> = ModeResultP<F, Mtbl<'a, F>, ParseError<'a, F>, I>;
/// [`FactoryParse`] equivalent of [`ExtensionResult`].
pub type ExtensionResultM<'a, Ctx, F> =
ExtensionResultP<F, Mtbl<'a, Ctx, F>, ParseError<'a, Ctx, F>>;
pub type ExtensionResultM<'a, F> = ExtensionResultP<F, Mtbl<'a, F>, ParseError<'a, F>>;
/// [`FactoryParse`] equivalent of [`ExtensionSource`].
pub type ExtensionSourceM<'a, Ctx, F> = ExtensionSourceP<F, Mtbl<'a, Ctx, F>>;
pub type ExtensionSourceM<'a, F> = ExtensionSourceP<F, Mtbl<'a, F>>;
/// 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<I: InCtx<'a, Ctx>>(&self, inctx: I) -> ModeResultM<'a, Ctx, Self, I>;
fn mdeserialize<I: InCtx<'a, Ctx>>(&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<I: InCtx<'a, Ctx>>(f: &Self::F, inctx: I) -> ModeResultM<'a, Ctx, Self::F, I>;
fn pmdeserialize<I: InCtx<'a, Ctx>>(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<I: InCtx<'a, Ctx>>(&self, inctx: I) -> ModeResultM<'a, Ctx, Self, I> {
fn mdeserialize<I: InCtx<'a, Ctx>>(&self, inctx: I) -> ModeResultM<'a, Self, I> {
<F::WithMode as FactoryModeProxy<'a, Ctx>>::pmdeserialize(self, inctx)
}
fn mextend(
&self,
mentionable: ExtensionSourceM<'a, Ctx, Self>,
mentionable: ExtensionSourceM<'a, Self>,
tail: &[u8],
) -> ExtensionResultM<'a, Ctx, Self> {
) -> ExtensionResultM<'a, Self> {
<F::WithMode as FactoryModeProxy<'a, Ctx>>::pmextend(self, mentionable, tail)
}
}

View File

@ -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, <O as Origin<'a, Ctx>>::Mtbl>;
pub type OFctr<'a, Ctx, O> = Fctr<'a, <O as Origin<'a, Ctx>>::Mtbl>;
/// [`OriginMap::resolve_map`].
pub trait OriginMap<'a, Ctx: Context<'a>>: Origin<'a, Ctx> {

View File

@ -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<dyn Origin<'a, Ctx, Mtbl = A>>,
}
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>,
{

View File

@ -2,34 +2,34 @@ use super::*;
/// For auto-deriving [`RegularFactory`] from concrete implementations.
pub trait CRegularFactory<'a, Ctx: Context<'a>>:
FactoryBase<'a, Ctx> + ImplMode<Mode = RegularMode>
FactoryBase<'a> + ImplMode<Mode = RegularMode>
{
/// 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<Mode = RegularMode>
FactoryBase<'a> + ParseMode<Mode = RegularMode>
{
/// 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<Mode = RegularMode>>
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<I: InCtx<'a, Ctx>>(f: &Self::F, inctx: I) -> ModeResultM<'a, Ctx, F, I> {
fn pmdeserialize<I: InCtx<'a, Ctx>>(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)
}
}

View File

@ -23,8 +23,7 @@ impl<L, P> ResolutionError<L, P> {
pub type LookupError<'a, Ctx> = <Ctx as Context<'a>>::LookupError;
/// See [`ResolutionResult`].
pub type ResolutionFailure<'a, Ctx, A> =
ResolutionError<LookupError<'a, Ctx>, ParseErrorA<'a, Ctx, A>>;
pub type ResolutionFailure<'a, Ctx, A> = ResolutionError<LookupError<'a, Ctx>, ParseErrorA<'a, A>>;
/// Result yielded by [`Origin`].
pub type ResolutionResult<'a, Ctx, A> = Result<Arc<A>, ResolutionFailure<'a, Ctx, A>>;

View File

@ -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<dyn Resolver<'a, Ctx>>,
@ -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> {

View File

@ -38,7 +38,7 @@ impl<A: AtomicBase> Serializable for AtomicObject<A> {
}
}
impl<'a, Ctx: Context<'a>, A: AtomicBase> MentionableBase<'a, Ctx> for AtomicObject<A> {
impl<'a, A: AtomicBase> MentionableBase<'a> for AtomicObject<A> {
type Fctr = AtomicFactory<A>;
fn factory(&self) -> Self::Fctr {
@ -71,7 +71,7 @@ impl<A: AtomicBase> Clone for AtomicFactory<A> {
}
}
impl<'a, Ctx: Context<'a>, A: AtomicBase> FactoryBase<'a, Ctx> for AtomicFactory<A> {
impl<'a, A: AtomicBase> FactoryBase<'a> for AtomicFactory<A> {
type Mtbl = AtomicObject<A>;
type ParseError = A::AParseError;
@ -82,15 +82,15 @@ impl<A: ParseMode> ParseMode for AtomicFactory<A> {
}
impl<'a, Ctx: Context<'a>, A: AtomicModeParse> FactoryModeParse<'a, Ctx> for AtomicFactory<A> {
fn mdeserialize<I: InCtx<'a, Ctx>>(&self, inctx: I) -> ModeResultM<'a, Ctx, Self, I> {
fn mdeserialize<I: InCtx<'a, Ctx>>(&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()),

View File

@ -152,7 +152,7 @@ impl<'a, Ctx: CastCtx<'a>> TypelessMentionable<'a, Ctx> {
&self,
factory: A::Fctr,
map_resolver: impl FnOnce(Arc<dyn Resolver<'a, Ctx>>) -> Arc<dyn Resolver<'a, Ctx>>,
) -> 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<A: Mentionable<'a, Ctx>>(&self, factory: A::Fctr) -> ParseResultA<'a, Ctx, A> {
pub fn cast<A: Mentionable<'a, Ctx>>(&self, factory: A::Fctr) -> ParseResultA<'a, A> {
self.cast_full(factory, identity)
}
}

View File

@ -10,7 +10,7 @@ use crate::rstd::inlining::static_pair::*;
use crate::rstd::inlining::*;
pub type PairObject<A, B> = 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<A: Serializable, B: Serializable> StaticPairSerializable for (A, B) {
type SA = A;
@ -46,8 +46,7 @@ impl<ErrorA: Error, ErrorB: Error> Display for PairParseError<ErrorA, ErrorB> {
impl<ErrorA: Error, ErrorB: Error> Error for PairParseError<ErrorA, ErrorB> {}
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, A::Fctr>, ParseError<'a, Ctx, B::Fctr>>;
type ParseError = PairParseError<ParseError<'a, A::Fctr>, 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<A: Serializable, B: Serializable> 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<FA::ParseError, FB::ParseError>;
@ -141,28 +136,22 @@ impl<A, B: ParseMode> ParseMode for (A, B) {
type Mode = B::Mode;
}
type PFImpl<'a, Ctx, FA, FB> = StaticPairFactory<
'a,
Ctx,
(
<FA as FactoryBase<'a, Ctx>>::Mtbl,
<FB as FactoryBase<'a, Ctx>>::Mtbl,
),
>;
type PFImpl<'a, FA, FB> =
StaticPairFactory<'a, (<FA as FactoryBase<'a>>::Mtbl, <FB as FactoryBase<'a>>::Mtbl)>;
impl<'a, Ctx: Context<'a>, FA: InliningFactory<'a, Ctx>, FB: FactoryModeParse<'a, Ctx>>
FactoryModeParse<'a, Ctx> for (FA, FB)
{
fn mdeserialize<I: InCtx<'a, Ctx>>(&self, inctx: I) -> ModeResultM<'a, Ctx, Self, I> {
PFImpl::<'a, Ctx, FA, FB>::mdeserialize_sp(self, inctx)
fn mdeserialize<I: InCtx<'a, Ctx>>(&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)
}
}

View File

@ -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<F> {
pub struct StackNodeFactory<Ctx, F> {
element_factory: F,
_ctx: PhantomData<Ctx>,
}
impl<F> StackNodeFactory<F> {
impl<Ctx, F: Clone> Clone for StackNodeFactory<Ctx, F> {
fn clone(&self) -> Self {
Self {
element_factory: self.element_factory.clone(),
_ctx: PhantomData,
}
}
}
impl<Ctx, F> StackNodeFactory<Ctx, F> {
fn new(factory: F) -> Self {
StackNodeFactory {
element_factory: factory,
_ctx: PhantomData,
}
}
}
impl<'a, Ctx: Context<'a>, A: MentionableBase<'a, Ctx>> Serializable for StackNode<'a, Ctx, A> {
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<A::Fctr>;
impl<'a, Ctx: Context<'a>, A: MentionableBase<'a>> MentionableBase<'a> for StackNode<'a, Ctx, A> {
type Fctr = StackNodeFactory<Ctx, A::Fctr>;
fn factory(&self) -> Self::Fctr {
StackNodeFactory::new(self.element.factory())
@ -85,34 +95,34 @@ impl<ElementParseError: Error> Display for StackParseError<ElementParseError> {
impl<ElementParseError: Error> Error for StackParseError<ElementParseError> {}
impl<F> StackNodeFactory<F> {
fn parse_point<'a, Ctx: Context<'a>, I: InCtx<'a, Ctx>>(
impl<'a, Ctx: Context<'a>, F> StackNodeFactory<Ctx, F> {
fn parse_point<I: InCtx<'a, Ctx>>(
&self,
inctx: I,
) -> IParseResult<'a, Ctx, NullableFactory<Self>, I>
) -> IParseResult<'a, NullableFactory<Ctx, Self>, I>
where
StackNodeFactory<F>: Factory<'a, Ctx>,
StackNodeFactory<Ctx, F>: Factory<'a, Ctx>,
{
NullableFactory::new(self.clone()).ideserialize(inctx)
}
}
impl<'a, Ctx: Context<'a>, F: FactoryBase<'a, Ctx>> FactoryBase<'a, Ctx> for StackNodeFactory<F> {
impl<'a, Ctx: Context<'a>, F: FactoryBase<'a>> FactoryBase<'a> for StackNodeFactory<Ctx, F> {
type Mtbl = StackNode<'a, Ctx, F::Mtbl>;
type ParseError = StackParseError<ParseError<'a, Ctx, F>>;
type ParseError = StackParseError<ParseError<'a, F>>;
}
impl<F: ParseMode> ParseMode for StackNodeFactory<F> {
impl<Ctx, F: ParseMode> ParseMode for StackNodeFactory<Ctx, F> {
type Mode = F::Mode;
}
impl<'a, Ctx: Context<'a>, F: FactoryModeParse<'a, Ctx>> FactoryModeParse<'a, Ctx>
for StackNodeFactory<F>
for StackNodeFactory<Ctx, F>
where
F::Mtbl: MentionableTop<'a, Ctx>,
{
fn mdeserialize<I: InCtx<'a, Ctx>>(&self, inctx: I) -> ModeResultM<'a, Ctx, Self, I> {
fn mdeserialize<I: InCtx<'a, Ctx>>(&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<F>
FixedSizeFactory<'a, Ctx> for StackNodeFactory<Ctx, F>
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<F>
ConstSizeFactory<'a, Ctx> for StackNodeFactory<Ctx, F>
where
F::Mtbl: MentionableTop<'a, Ctx>,
{
@ -168,9 +178,7 @@ pub type StackVecResult<'a, Ctx, A> = Result<Vec<A>, 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<A::Fctr>>,
StackNode<'a, Ctx, A>: Mentionable<'a, Ctx, _Fctr = StackNodeFactory<Ctx, A::Fctr>>,
{
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<A::Fctr>>,
StackNodeFactory<A::Fctr>: FactoryParse<'a, Ctx>,
StackNode<'a, Ctx, A>: Mentionable<'a, Ctx, _Fctr = StackNodeFactory<Ctx, A::Fctr>>,
StackNodeFactory<Ctx, A::Fctr>: FactoryParse<'a, Ctx>,
{
fn vec(self) -> StackVecWrapped<'a, Ctx, A> {
Ctx::T::iterate_mut((vec![], self), |(mut vec, stack)| match stack {

View File

@ -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<E: Display> Display for TreeParseError<E> {
impl<E: Error> Error for TreeParseError<E> {}
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>(F);
pub struct NodeFactory<Ctx, F> {
factory: F,
_ctx: PhantomData<Ctx>,
}
#[derive(Clone)]
pub struct TreeFactory<F>(NullableFactory<NodeFactory<F>>);
impl<Ctx, F: Clone> Clone for NodeFactory<Ctx, F> {
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<Ctx, F>(NullableFactory<Ctx, NodeFactory<Ctx, F>>);
impl<Ctx, F: Clone> Clone for TreeFactory<Ctx, F> {
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<A::Fctr>;
impl<'a, Ctx: Context<'a>, A: MentionableBase<'a>> MentionableBase<'a> for Node<'a, Ctx, A> {
type Fctr = NodeFactory<Ctx, A::Fctr>;
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<A::Fctr>;
impl<'a, Ctx: Context<'a>, A: MentionableBase<'a>> MentionableBase<'a> for Tree<'a, Ctx, A> {
type Fctr = TreeFactory<Ctx, A::Fctr>;
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<F> {
impl<'a, Ctx: Context<'a>, F: FactoryBase<'a>> FactoryBase<'a> for NodeFactory<Ctx, F> {
type Mtbl = Node<'a, Ctx, F::Mtbl>;
type ParseError = TreeParseError<F::ParseError>;
}
impl<F: ParseMode> ParseMode for NodeFactory<F> {
impl<Ctx, F: ParseMode> ParseMode for NodeFactory<Ctx, F> {
type Mode = F::Mode;
}
impl<'a, Ctx: Context<'a>, F: FactoryModeParse<'a, Ctx>> FactoryModeParse<'a, Ctx>
for NodeFactory<F>
for NodeFactory<Ctx, F>
{
fn mdeserialize<I: InCtx<'a, Ctx>>(&self, inctx: I) -> ModeResultM<'a, Ctx, Self, I> {
fn mdeserialize<I: InCtx<'a, Ctx>>(&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<F> {
impl<'a, Ctx: Context<'a>, F: FactoryBase<'a>> FactoryBase<'a> for TreeFactory<Ctx, F> {
type Mtbl = Tree<'a, Ctx, F::Mtbl>;
type ParseError = TreeParseError<F::ParseError>;
}
impl<F> ImplMode for TreeFactory<F> {
impl<Ctx, F> ImplMode for TreeFactory<Ctx, F> {
type Mode = InliningMode;
}
impl<'a, Ctx: Context<'a>, F: FactoryParse<'a, Ctx>> CInliningFactory<'a, Ctx> for TreeFactory<F> {
impl<'a, Ctx: Context<'a>, F: FactoryParse<'a, Ctx>> CInliningFactory<'a, Ctx>
for TreeFactory<Ctx, F>
{
fn cextension_error(&self, tail: &[u8]) -> Self::ParseError {
u64::a_extension_error(tail).into()
}
fn cideserialize<I: InCtx<'a, Ctx>>(&self, inctx: I) -> IParseResult<'a, Ctx, Self, I> {
fn cideserialize<I: InCtx<'a, Ctx>>(&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(),

View File

@ -38,12 +38,12 @@ impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>, E: 'a>
}
}
type TreeParseError2<'a, Ctx, A> = TreeParseError<ParseErrorA<'a, Ctx, A>>;
type TreeParseError2<'a, A> = TreeParseError<ParseErrorA<'a, A>>;
impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>, E: 'a> From<TreeParseError2<'a, Ctx, A>>
impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>, E: 'a> From<TreeParseError2<'a, A>>
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<HeightError>
}
}
pub type TreeContext2<'a, Ctx, A, C, E> =
TreeContext<(Arc<C>, Fctr<'a, Ctx, A>), (&'a (), Ctx, A, E)>;
pub type TreeContext2<'a, Ctx, A, C, E> = TreeContext<(Arc<C>, 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,
}
}

View File

@ -6,10 +6,7 @@ use crate::rstd::{singular::*, *};
pub trait Inject<'a, Ctx: Context<'a>>: 'a + Send + Sync + Sized {
fn inject<A: 'a + Send>(&self, fa: Wrapped<'a, Ctx, A>) -> Wrapped<'a, Ctx, A>;
fn inject_mentionable<A: Mentionable<'a, Ctx>>(
self: Arc<Self>,
a: &A,
) -> ParseResultA<'a, Ctx, A> {
fn inject_mentionable<A: Mentionable<'a, Ctx>>(self: Arc<Self>, a: &A) -> ParseResultA<'a, A> {
let factory = a.factory();
let inject = self;
let resolver = SingularResolver::from_mentionable(a).into_rc();

View File

@ -122,15 +122,15 @@ impl<P: Error> From<P> for CheckedParseError<P> {
}
}
pub type CheckedParseFailure<'a, Ctx, F> = CheckedParseError<ParseError<'a, Ctx, F>>;
pub type CheckedParseFailure<'a, F> = CheckedParseError<ParseError<'a, F>>;
/// Returned by [`CheckedParse::deserialize_checked`].
pub type CheckedParseResult<'a, Ctx, F> = Result<Mtbl<'a, Ctx, F>, CheckedParseFailure<'a, Ctx, F>>;
pub type CheckedParseResult<'a, F> = Result<Mtbl<'a, F>, 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)?;

View File

@ -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<SA = Self::A, SB = Self::B> + 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<SP> Deref for StaticPairObject<SP> {
}
/// 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<SP: StaticPairSerializable> Serializable for StaticPairObject<SP> {
}
}
impl<'a, Ctx: Context<'a>, SP: StaticPair<'a, Ctx>> MentionableBase<'a, Ctx>
for StaticPairObject<SP>
{
type Fctr = StaticPairFactory<'a, Ctx, SP>;
impl<'a, SP: StaticPair<'a>> MentionableBase<'a> for StaticPairObject<SP> {
type Fctr = StaticPairFactory<'a, SP>;
fn factory(&self) -> Self::Fctr {
StaticPairFactory {
@ -129,7 +127,7 @@ impl<SP> StaticPairObject<SP> {
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<SP> StaticPairObject<SP> {
}
}
impl<'a, Ctx: Context<'a>, SP: StaticPair<'a, Ctx>> MentionableTop<'a, Ctx> for StaticPairObject<SP>
impl<'a, Ctx: Context<'a>, SP: StaticPair<'a>> MentionableTop<'a, Ctx> for StaticPairObject<SP>
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<SP>;
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 = <SP::FB as ParseMode>::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<I: InCtx<'a, Ctx>>(
impl<'a, SP: StaticPair<'a>> StaticPairFactory<'a, SP> {
pub fn mdeserialize_sp<Ctx: Context<'a>, I: InCtx<'a, Ctx>>(
factory_data: &SP::FactoryData,
inctx: I,
) -> ModeResultP<Self, SP, SP::ParseError, I> {
) -> ModeResultP<Self, SP, SP::ParseError, I>
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<Ctx: Context<'a>>(
factory_data: &SP::FactoryData,
mentionable: ExtensionSourceP<Self, SP>,
tail: &[u8],
) -> ExtensionResultP<Self, SP, SP::ParseError> {
) -> ExtensionResultP<Self, SP, SP::ParseError>
where
SP::FA: InliningFactory<'a, Ctx>,
SP::FB: FactoryModeParse<'a, Ctx>,
{
let (_, fb) = SP::factories(factory_data);
// annotated to help rust-analyzer
Self::xsbind::<SP, _, _, _>(
@ -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<I: InCtx<'a, Ctx>>(&self, inctx: I) -> ModeResultM<'a, Ctx, Self, I> {
fn mdeserialize<I: InCtx<'a, Ctx>>(&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>,

View File

@ -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<F> {
pub struct NullableFactory<Ctx, F> {
/// Factory of the referenced object.
factory: F,
_ctx: PhantomData<Ctx>,
}
impl<'a, Ctx: Context<'a>, A: MentionableBase<'a, Ctx>> Serializable for Nullable<'a, Ctx, A> {
impl<Ctx, F: Clone> Clone for NullableFactory<Ctx, F> {
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<A::Fctr>;
impl<'a, Ctx: Context<'a>, A: MentionableBase<'a>> MentionableBase<'a> for Nullable<'a, Ctx, A> {
type Fctr = NullableFactory<Ctx, A::Fctr>;
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<F> {
impl<'a, Ctx: Context<'a>, F: FactoryBase<'a>> FactoryBase<'a> for NullableFactory<Ctx, F> {
type Mtbl = Nullable<'a, Ctx, F::Mtbl>;
type ParseError = PointParseError;
}
impl<F> ImplMode for NullableFactory<F> {
impl<Ctx, F> ImplMode for NullableFactory<Ctx, F> {
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<F> NullableFactory<F> {
impl<Ctx, F> NullableFactory<Ctx, F> {
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<F>
impl<'a, Ctx: Context<'a>, F: FactoryBase<'a>> CInliningFactory<'a, Ctx>
for NullableFactory<Ctx, F>
{
fn cextension_error(&self, tail: &[u8]) -> Self::ParseError {
PointParseError::WrongLength(HASH_SIZE + tail.len())
}
fn cideserialize<I: InCtx<'a, Ctx>>(&self, inctx: I) -> IParseResult<'a, Ctx, Self, I> {
fn cideserialize<I: InCtx<'a, Ctx>>(&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<F> AlwaysConstSize for NullableFactory<F> {
impl<Ctx, F> AlwaysConstSize for NullableFactory<Ctx, F> {
const _SIZE: usize = HASH_SIZE;
}

View File

@ -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<A::Fctr>;
impl<'a, Ctx: Context<'a>, A: MentionableBase<'a>> MentionableBase<'a> for Point<'a, Ctx, A> {
type Fctr = PointFactory<Ctx, A::Fctr>;
fn factory(&self) -> Self::Fctr {
PointFactory {
factory: self.origin.factory(),
PointFactory::new(self.origin.factory())
}
}
impl<Ctx, F> PointFactory<Ctx, F> {
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<F> {
pub struct PointFactory<Ctx, F> {
factory: F,
_ctx: PhantomData<Ctx>,
}
impl<F: Clone> PointFactory<F> {
impl<Ctx, F: Clone> Clone for PointFactory<Ctx, F> {
fn clone(&self) -> Self {
Self::new(self.factory.clone())
}
}
impl<Ctx, F: Clone> PointFactory<Ctx, F> {
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<F> {
impl<'a, Ctx: Context<'a>, F: FactoryBase<'a>> FactoryBase<'a> for PointFactory<Ctx, F> {
type Mtbl = Point<'a, Ctx, F::Mtbl>;
type ParseError = PointParseError;
}
impl<F> ImplMode for PointFactory<F> {
impl<Ctx, F> ImplMode for PointFactory<Ctx, F> {
type Mode = InliningMode;
}
impl<'a, Ctx: Context<'a>, F: FactoryBase<'a, Ctx>> CInliningFactory<'a, Ctx> for PointFactory<F> {
impl<'a, Ctx: Context<'a>, F: FactoryBase<'a>> CInliningFactory<'a, Ctx> for PointFactory<Ctx, F> {
fn cextension_error(&self, tail: &[u8]) -> Self::ParseError {
PointParseError::WrongLength(HASH_SIZE + tail.len())
}
fn cideserialize<I: InCtx<'a, Ctx>>(&self, inctx: I) -> IParseResult<'a, Ctx, Self, I> {
fn cideserialize<I: InCtx<'a, Ctx>>(&self, inctx: I) -> IParseResult<'a, Self, I> {
inctx.icnext_point(self.inner(), PointParseError::from_ref)
}
}
impl<F> AlwaysConstSize for PointFactory<F> {
impl<Ctx, F> AlwaysConstSize for PointFactory<Ctx, F> {
const _SIZE: usize = HASH_SIZE;
}

View File

@ -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)
}
}

View File

@ -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)
}
}

View File

@ -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<dyn Origin<'a, Ctx, Mtbl = B>>
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<A>) -> 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()
}

View File

@ -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)
}
}