58 lines
1.9 KiB
Rust
58 lines
1.9 KiB
Rust
use super::*;
|
|
|
|
/// Inlining version of [`ParseResult`]. Preserves the parser.
|
|
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> + 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, Self, I>;
|
|
}
|
|
|
|
/// Factory preserving the parser on success.
|
|
pub trait InliningFactory<'a, Ctx: Context<'a>>:
|
|
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, Self, I>;
|
|
}
|
|
|
|
impl<'a, Ctx: Context<'a>, F: FactoryModeParse<'a, Ctx> + ParseMode<Mode = InliningMode>>
|
|
InliningFactory<'a, Ctx> for F
|
|
{
|
|
fn extension_error(&self, tail: &[u8]) -> Self::ParseError {
|
|
self.mextend((), tail)
|
|
}
|
|
|
|
fn ideserialize<I: InCtx<'a, Ctx>>(&self, inctx: I) -> IParseResult<'a, Self, I> {
|
|
self.mdeserialize(inctx)
|
|
}
|
|
}
|
|
|
|
impl<'a, Ctx: Context<'a>, F: CInliningFactory<'a, Ctx>> FactoryModeProxy<'a, Ctx>
|
|
for WithMode<F, InliningMode>
|
|
{
|
|
type F = F;
|
|
|
|
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, F>,
|
|
tail: &[u8],
|
|
) -> ExtensionResultM<'a, F> {
|
|
f.cextension_error(tail)
|
|
}
|
|
}
|