radn-rs/src/rcore/inlining.rs
timofey 3c095f0fb5
Some checks failed
buildbot/cargo fmt (1.72) Build done.
buildbot/cargo clippy (1.72) Build done.
buildbot/cargo doc (1.72) Build done.
buildbot/cargo test (1.65) Build done.
buildbot/cargo clippy (1.65) Build done.
remove Ctx from bases
2023-08-31 23:07:12 +00:00

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)
}
}