FactoryParse
via FactoryModeParse
This commit is contained in:
parent
4a9c2c0c3b
commit
486d7e7af8
@ -28,6 +28,8 @@ pub trait Mode {
|
|||||||
result: Self::ExtensionResult<A0, E>,
|
result: Self::ExtensionResult<A0, E>,
|
||||||
f: impl FnOnce(A0) -> Result<A1, E>,
|
f: impl FnOnce(A0) -> Result<A1, E>,
|
||||||
) -> Self::ExtensionResult<A1, E>;
|
) -> Self::ExtensionResult<A1, E>;
|
||||||
|
|
||||||
|
fn xseal<A, E>(result: Self::ExtensionResult<A, E>) -> Result<A, E>;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait ParseMode {
|
pub trait ParseMode {
|
||||||
@ -55,16 +57,13 @@ pub trait FactoryProxy<'a, Ctx: Context<'a>> {
|
|||||||
) -> ParseResult<'a, Ctx, Self::F>;
|
) -> ParseResult<'a, Ctx, Self::F>;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, Ctx: Context<'a>, F: FactoryBase<'a, Ctx> + WithParseMode> FactoryParse<'a, Ctx> for F
|
impl<'a, Ctx: Context<'a>, F: FactoryModeParse<'a, Ctx>> FactoryParse<'a, Ctx> for F {
|
||||||
where
|
|
||||||
F::WithMode: FactoryProxy<'a, Ctx, F = Self>,
|
|
||||||
{
|
|
||||||
fn deserialize(&self, inctx: impl InCtx<'a, Ctx>) -> ParseResult<'a, Ctx, Self> {
|
fn deserialize(&self, inctx: impl InCtx<'a, Ctx>) -> ParseResult<'a, Ctx, Self> {
|
||||||
<F::WithMode as FactoryProxy<'a, Ctx>>::pdeserialize(self, inctx)
|
<<Self as ParseMode>::Mode as Mode>::seal(self.mdeserialize(inctx))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn extend(&self, mentionable: Self::Mtbl, tail: &[u8]) -> ParseResult<'a, Ctx, Self> {
|
fn extend(&self, mentionable: Self::Mtbl, tail: &[u8]) -> ParseResult<'a, Ctx, Self> {
|
||||||
<F::WithMode as FactoryProxy<'a, Ctx>>::pextend(self, mentionable, tail)
|
<<Self as ParseMode>::Mode as Mode>::xseal(self.mextend(mentionable, tail))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -149,6 +148,10 @@ impl Mode for RegularMode {
|
|||||||
) -> Self::ExtensionResult<A1, E> {
|
) -> Self::ExtensionResult<A1, E> {
|
||||||
result.and_then(f)
|
result.and_then(f)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn xseal<A, E>(result: Self::ExtensionResult<A, E>) -> Result<A, E> {
|
||||||
|
result
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait RegularFactory<'a, Ctx: Context<'a>>:
|
pub trait RegularFactory<'a, Ctx: Context<'a>>:
|
||||||
|
@ -40,6 +40,10 @@ impl Mode for InliningMode {
|
|||||||
) -> Self::ExtensionResult<A1, E> {
|
) -> Self::ExtensionResult<A1, E> {
|
||||||
result
|
result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn xseal<A, E>(result: Self::ExtensionResult<A, E>) -> Result<A, E> {
|
||||||
|
Err(result)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, Ctx: Context<'a>, F: InlineableFactory<'a, Ctx>> FactoryProxy<'a, Ctx>
|
impl<'a, Ctx: Context<'a>, F: InlineableFactory<'a, Ctx>> FactoryProxy<'a, Ctx>
|
||||||
|
Loading…
Reference in New Issue
Block a user