74 lines
2.5 KiB
Rust
74 lines
2.5 KiB
Rust
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, Self> {
|
|
self.mdeserialize(inctx).map(Self::seal)
|
|
}
|
|
|
|
fn extend(&self, mentionable: Self::Mtbl, tail: &[u8]) -> ParseResult<'a, Self> {
|
|
Self::xseal(self.mextend(Self::prepare(mentionable), tail))
|
|
}
|
|
}
|
|
|
|
impl<'a, Ctx: Context<'a>, F: FactoryParse<'a, Ctx> + ParseMode> Factory<'a, Ctx> for F
|
|
where
|
|
F::Mtbl: MentionableTop<'a, Ctx>,
|
|
{
|
|
type _Mtbl = Self::Mtbl;
|
|
}
|
|
|
|
/// [`FactoryParse`] equivalent of [`ModeResult`].
|
|
pub type ModeResultM<'a, F, I> = ModeResultP<F, Mtbl<'a, F>, ParseError<'a, F>, I>;
|
|
|
|
/// [`FactoryParse`] equivalent of [`ExtensionResult`].
|
|
pub type ExtensionResultM<'a, F> = ExtensionResultP<F, Mtbl<'a, F>, ParseError<'a, F>>;
|
|
|
|
/// [`FactoryParse`] equivalent of [`ExtensionSource`].
|
|
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> + ParseMode {
|
|
/// A more generic version of [`FactoryParse::deserialize`].
|
|
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, Self>,
|
|
tail: &[u8],
|
|
) -> ExtensionResultM<'a, Self>;
|
|
}
|
|
|
|
/// External implementation of [`FactoryModeParse`].
|
|
pub trait FactoryModeProxy<'a, Ctx: Context<'a>> {
|
|
/// Associated [`FactoryModeParse`].
|
|
type F: FactoryBase<'a> + ParseMode;
|
|
|
|
/// External implementation of [`FactoryModeParse::mdeserialize`].
|
|
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, Self::F>,
|
|
tail: &[u8],
|
|
) -> ExtensionResultM<'a, Self::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, Self, I> {
|
|
<F::WithMode as FactoryModeProxy<'a, Ctx>>::pmdeserialize(self, inctx)
|
|
}
|
|
|
|
fn mextend(
|
|
&self,
|
|
mentionable: ExtensionSourceM<'a, Self>,
|
|
tail: &[u8],
|
|
) -> ExtensionResultM<'a, Self> {
|
|
<F::WithMode as FactoryModeProxy<'a, Ctx>>::pmextend(self, mentionable, tail)
|
|
}
|
|
}
|