78 lines
1.9 KiB
Rust
78 lines
1.9 KiB
Rust
use super::*;
|
|
|
|
pub struct InliningMode;
|
|
|
|
impl Mode for InliningMode {
|
|
type ParseResult<A, E, I> = Result<(A, I), E>;
|
|
|
|
type ExtensionResult<A, E> = E;
|
|
|
|
fn map_err<A, E0, E1, I>(
|
|
result: Self::ParseResult<A, E0, I>,
|
|
f: impl FnOnce(E0) -> E1,
|
|
) -> Self::ParseResult<A, E1, I> {
|
|
result.map_err(f)
|
|
}
|
|
|
|
fn bind<A0, A1, E, I>(
|
|
result: Self::ParseResult<A0, E, I>,
|
|
f: impl FnOnce(A0) -> Result<A1, E>,
|
|
) -> Self::ParseResult<A1, E, I> {
|
|
let (a0, i) = result?;
|
|
let a1 = f(a0)?;
|
|
Ok((a1, i))
|
|
}
|
|
|
|
fn seal<A, E, I>(result: Self::ParseResult<A, E, I>) -> Result<A, E> {
|
|
result.map(|(a, _)| a)
|
|
}
|
|
|
|
fn xmap_err<A, E0, E1>(
|
|
result: Self::ExtensionResult<A, E0>,
|
|
f: impl FnOnce(E0) -> E1,
|
|
) -> Self::ExtensionResult<A, E1> {
|
|
f(result)
|
|
}
|
|
|
|
fn xbind<A0, A1, E>(
|
|
result: Self::ExtensionResult<A0, E>,
|
|
_f: impl FnOnce(A0) -> Result<A1, E>,
|
|
) -> Self::ExtensionResult<A1, E> {
|
|
result
|
|
}
|
|
|
|
fn xseal<A, E>(result: Self::ExtensionResult<A, E>) -> Result<A, E> {
|
|
Err(result)
|
|
}
|
|
}
|
|
|
|
impl<'a, Ctx: Context<'a>, F: InlineableFactory<'a, Ctx>> FactoryModeProxy<'a, Ctx>
|
|
for WithMode<F, InliningMode>
|
|
{
|
|
type F = F;
|
|
|
|
fn pmdeserialize<I: InCtx<'a, Ctx>>(f: &Self::F, inctx: I) -> ParseResultM<'a, Ctx, F, I> {
|
|
f.ideserialize(inctx)
|
|
}
|
|
|
|
fn pmextend(
|
|
f: &F,
|
|
_mentionable: Mtbl<'a, Ctx, F>,
|
|
tail: &[u8],
|
|
) -> ExtensionResultM<'a, Ctx, F> {
|
|
f.extension_error(tail)
|
|
}
|
|
}
|
|
|
|
impl<A: InlineableAtomic> AtomicProxy for WithMode<A, InliningMode> {
|
|
type A = A;
|
|
|
|
fn pa_deserialize(inlining: impl Inlining) -> AParseResult<Self::A> {
|
|
A::a_ideserialize(inlining).seal()
|
|
}
|
|
|
|
fn pa_extend(_a: Self::A, tail: &[u8]) -> AParseResult<Self::A> {
|
|
Err(A::a_extension_error(tail))
|
|
}
|
|
}
|