diff --git a/src/rcore.rs b/src/rcore.rs index 40816d5..88257d1 100644 --- a/src/rcore.rs +++ b/src/rcore.rs @@ -13,6 +13,7 @@ mod modes; mod origin; mod point; mod points; +mod regular; mod resolution; mod resolver_origin; @@ -30,12 +31,12 @@ pub use self::diagnostic::Diagnostic; pub use self::hashing::{Hash, HASH_SIZE, HASH_ZEROS}; pub use self::inctx::InCtx; pub use self::modes::{ - CRegularFactory, ExtensionResultM, ExtensionSourceM, FactoryModeParse, FactoryModeProxy, - ModeResultM, RegularFactory, + ExtensionResultM, ExtensionSourceM, FactoryModeParse, FactoryModeProxy, ModeResultM, }; pub use self::origin::{OFctr, Origin}; pub use self::point::Point; pub use self::points::PointsVisitor; +pub use self::regular::{CRegularFactory, RegularFactory}; pub use self::resolution::{ Address, HashResolution, HashResolutionResult, LookupError, Resolution, ResolutionError, ResolutionFailure, ResolutionResult, Resolver, ResolverMap, diff --git a/src/rcore/modes.rs b/src/rcore/modes.rs index 7a5c8aa..d9a55a4 100644 --- a/src/rcore/modes.rs +++ b/src/rcore/modes.rs @@ -72,49 +72,3 @@ where >::pmextend(self, mentionable, tail) } } - -/// For auto-deriving [`RegularFactory`] from concrete implementations. -pub trait CRegularFactory<'a, Ctx: Context<'a>>: - FactoryBase<'a, Ctx> + ImplMode -{ - /// Concrete implementation of [`RegularFactory::rdeserialize`]. - fn crdeserialize(&self, inctx: impl InCtx<'a, Ctx>) -> ParseResult<'a, Ctx, Self>; - /// Concrete implementation of [`RegularFactory::rextend`]. - fn crextend(&self, mentionable: Self::Mtbl, tail: &[u8]) -> ParseResult<'a, Ctx, Self>; -} - -/// Mostly same as [`FactoryModeParse`] but requires [`Mode`] to be [`RegularMode`]. -pub trait RegularFactory<'a, Ctx: Context<'a>>: - FactoryBase<'a, Ctx> + ParseMode -{ - /// Same as [`FactoryModeParse::mdeserialize`]. - fn rdeserialize(&self, inctx: impl InCtx<'a, Ctx>) -> ParseResult<'a, Ctx, Self>; - /// Same as [`FactoryModeParse::mextend`]. - fn rextend(&self, mentionable: Self::Mtbl, tail: &[u8]) -> ParseResult<'a, Ctx, 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> { - self.mdeserialize(inctx) - } - - fn rextend(&self, mentionable: Self::Mtbl, tail: &[u8]) -> ParseResult<'a, Ctx, Self> { - self.mextend(mentionable, tail) - } -} - -impl<'a, Ctx: Context<'a>, F: CRegularFactory<'a, Ctx>> FactoryModeProxy<'a, Ctx> - for WithMode -{ - type F = F; - - fn pmdeserialize>(f: &Self::F, inctx: I) -> ModeResultM<'a, Ctx, F, I> { - f.crdeserialize(inctx) - } - - fn pmextend(f: &F, mentionable: Mtbl<'a, Ctx, F>, tail: &[u8]) -> ExtensionResultM<'a, Ctx, F> { - f.crextend(mentionable, tail) - } -} diff --git a/src/rcore/regular.rs b/src/rcore/regular.rs new file mode 100644 index 0000000..120e461 --- /dev/null +++ b/src/rcore/regular.rs @@ -0,0 +1,47 @@ +use super::*; + +/// For auto-deriving [`RegularFactory`] from concrete implementations. +pub trait CRegularFactory<'a, Ctx: Context<'a>>: + FactoryBase<'a, Ctx> + ImplMode +{ + /// Concrete implementation of [`RegularFactory::rdeserialize`]. + fn crdeserialize(&self, inctx: impl InCtx<'a, Ctx>) -> ParseResult<'a, Ctx, Self>; + /// Concrete implementation of [`RegularFactory::rextend`]. + fn crextend(&self, mentionable: Self::Mtbl, tail: &[u8]) -> ParseResult<'a, Ctx, Self>; +} + +/// Mostly same as [`FactoryModeParse`] but requires [`Mode`] to be [`RegularMode`]. +pub trait RegularFactory<'a, Ctx: Context<'a>>: + FactoryBase<'a, Ctx> + ParseMode +{ + /// Same as [`FactoryModeParse::mdeserialize`]. + fn rdeserialize(&self, inctx: impl InCtx<'a, Ctx>) -> ParseResult<'a, Ctx, Self>; + /// Same as [`FactoryModeParse::mextend`]. + fn rextend(&self, mentionable: Self::Mtbl, tail: &[u8]) -> ParseResult<'a, Ctx, 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> { + self.mdeserialize(inctx) + } + + fn rextend(&self, mentionable: Self::Mtbl, tail: &[u8]) -> ParseResult<'a, Ctx, Self> { + self.mextend(mentionable, tail) + } +} + +impl<'a, Ctx: Context<'a>, F: CRegularFactory<'a, Ctx>> FactoryModeProxy<'a, Ctx> + for WithMode +{ + type F = F; + + fn pmdeserialize>(f: &Self::F, inctx: I) -> ModeResultM<'a, Ctx, F, I> { + f.crdeserialize(inctx) + } + + fn pmextend(f: &F, mentionable: Mtbl<'a, Ctx, F>, tail: &[u8]) -> ExtensionResultM<'a, Ctx, F> { + f.crextend(mentionable, tail) + } +}