rcore::inlining
This commit is contained in:
parent
c1c15c1c6b
commit
ce65688e47
@ -10,7 +10,7 @@ pub trait CInliningAtomic: AtomicBase + ImplMode<Mode = InliningMode> {
|
||||
|
||||
/// Atomic analogue of [`InliningFactory`]/[`InliningObject`].
|
||||
///
|
||||
/// [`InliningFactory`]: crate::rstd::inlining::InliningFactory
|
||||
/// [`InliningFactory`]: crate::rcore::InliningFactory
|
||||
/// [`InliningObject`]: crate::rstd::inlining::InliningObject
|
||||
pub trait InliningAtomic: AtomicBase + ParseMode<Mode = InliningMode> {
|
||||
fn a_extension_error(tail: &[u8]) -> Self::AParseError;
|
||||
@ -27,3 +27,15 @@ impl<A: AtomicModeParse + ParseMode<Mode = InliningMode>> InliningAtomic for A {
|
||||
A::ma_deserialize(stream)
|
||||
}
|
||||
}
|
||||
|
||||
impl<A: CInliningAtomic> AtomicModeProxy for WithMode<A, InliningMode> {
|
||||
type A = A;
|
||||
|
||||
fn pma_deserialize<I: Stream>(stream: I) -> AModeResultM<Self::A, I> {
|
||||
A::ca_ideserialize(stream)
|
||||
}
|
||||
|
||||
fn pma_extend(_atomic: AExtensionSourceM<Self::A>, tail: &[u8]) -> AExtensionResultM<Self::A> {
|
||||
A::ca_extension_error(tail)
|
||||
}
|
||||
}
|
||||
|
@ -56,7 +56,7 @@ pub trait Mode {
|
||||
///
|
||||
/// See also [`Mode::map`]
|
||||
///
|
||||
/// [`InliningFactory`]: crate::rstd::inlining::InliningFactory
|
||||
/// [`InliningFactory`]: crate::rcore::InliningFactory
|
||||
fn bind<A0, A1, E, I>(
|
||||
s: Self::ParseSuccess<A0, I>,
|
||||
f: impl FnOnce(A0) -> Result<A1, E>,
|
||||
@ -79,7 +79,7 @@ pub trait Mode {
|
||||
///
|
||||
/// Useful for for wrappers and chaining parsing after [`InliningFactory`].
|
||||
///
|
||||
/// [`InliningFactory`]: crate::rstd::inlining::InliningFactory
|
||||
/// [`InliningFactory`]: crate::rcore::InliningFactory
|
||||
fn xmap_err<A, E0, E1>(
|
||||
result: Self::ExtensionResult<A, E0>,
|
||||
f: impl FnOnce(E0) -> E1,
|
||||
@ -89,7 +89,7 @@ pub trait Mode {
|
||||
///
|
||||
/// Useful for wrappers and chaining extension after [`InliningFactory`].
|
||||
///
|
||||
/// [`InliningFactory`]: crate::rstd::inlining::InliningFactory
|
||||
/// [`InliningFactory`]: crate::rcore::InliningFactory
|
||||
fn xbind<A0, A1, E>(
|
||||
result: Self::ExtensionResult<A0, E>,
|
||||
f: impl FnOnce(A0) -> Result<A1, E>,
|
||||
|
@ -2,7 +2,7 @@ use super::*;
|
||||
|
||||
/// [`Mode`] for [`InliningFactory`].
|
||||
///
|
||||
/// [`InliningFactory`]: crate::rstd::inlining::InliningFactory
|
||||
/// [`InliningFactory`]: crate::rcore::InliningFactory
|
||||
/// [`InliningAtomic`]: crate::rstd::atomic::InliningAtomic
|
||||
pub struct InliningMode;
|
||||
|
||||
|
@ -9,6 +9,7 @@ mod demoted;
|
||||
mod diagnostic;
|
||||
mod hashing;
|
||||
mod inctx;
|
||||
mod inlining;
|
||||
mod modes;
|
||||
mod origin;
|
||||
mod point;
|
||||
@ -30,6 +31,7 @@ pub use self::demoted::Demoted;
|
||||
pub use self::diagnostic::Diagnostic;
|
||||
pub use self::hashing::{Hash, HASH_SIZE, HASH_ZEROS};
|
||||
pub use self::inctx::InCtx;
|
||||
pub use self::inlining::{CInliningFactory, IParseResult, InliningFactory};
|
||||
pub use self::modes::{
|
||||
ExtensionResultM, ExtensionSourceM, FactoryModeParse, FactoryModeProxy, ModeResultM,
|
||||
};
|
||||
|
50
src/rcore/inlining.rs
Normal file
50
src/rcore/inlining.rs
Normal file
@ -0,0 +1,50 @@
|
||||
use super::*;
|
||||
|
||||
pub type IParseResult<'a, Ctx, F, I> = Result<(Mtbl<'a, Ctx, F>, I), ParseError<'a, Ctx, F>>;
|
||||
|
||||
pub trait CInliningFactory<'a, Ctx: Context<'a>>:
|
||||
FactoryBase<'a, Ctx> + ImplMode<Mode = InliningMode>
|
||||
{
|
||||
fn cextension_error(&self, tail: &[u8]) -> Self::ParseError;
|
||||
|
||||
fn cideserialize<I: InCtx<'a, Ctx>>(&self, inctx: I) -> IParseResult<'a, Ctx, Self, I>;
|
||||
}
|
||||
|
||||
/// This factory should return an error on EOF.
|
||||
pub trait InliningFactory<'a, Ctx: Context<'a>>:
|
||||
FactoryBase<'a, Ctx> + ParseMode<Mode = InliningMode>
|
||||
{
|
||||
fn extension_error(&self, tail: &[u8]) -> Self::ParseError;
|
||||
|
||||
fn ideserialize<I: InCtx<'a, Ctx>>(&self, inctx: I) -> IParseResult<'a, Ctx, 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, Ctx, 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, Ctx, F, I> {
|
||||
f.cideserialize(inctx)
|
||||
}
|
||||
|
||||
fn pmextend(
|
||||
f: &F,
|
||||
_mentionable: ExtensionSourceM<'a, Ctx, F>,
|
||||
tail: &[u8],
|
||||
) -> ExtensionResultM<'a, Ctx, F> {
|
||||
f.cextension_error(tail)
|
||||
}
|
||||
}
|
@ -5,7 +5,7 @@ use std::fmt::Display;
|
||||
|
||||
use crate::mode::*;
|
||||
use crate::rcore::*;
|
||||
use crate::rstd::inlining::{static_pair::*, *};
|
||||
use crate::rstd::inlining::static_pair::*;
|
||||
|
||||
pub type PairObject<A, B> = StaticPairObject<(A, B)>;
|
||||
pub type PairFactory<'a, Ctx, A, B> = StaticPairFactory<'a, Ctx, (A, B)>;
|
||||
|
@ -7,7 +7,7 @@ use crate::{
|
||||
flow::binary::*,
|
||||
mode::*,
|
||||
rcore::*,
|
||||
rstd::{atomic::au64::*, inlining::*, nullable::*, point::*},
|
||||
rstd::{atomic::au64::*, nullable::*, point::*},
|
||||
};
|
||||
|
||||
#[derive(Debug)]
|
||||
|
@ -1,6 +1,5 @@
|
||||
//! Traits to better express parsing semantics.
|
||||
|
||||
mod modes;
|
||||
pub mod static_pair;
|
||||
|
||||
use crate::atomic::*;
|
||||
@ -9,37 +8,6 @@ use crate::rcore::*;
|
||||
|
||||
use super::{atomic_object::*, *};
|
||||
|
||||
pub type IParseResult<'a, Ctx, F, I> = Result<(Mtbl<'a, Ctx, F>, I), ParseError<'a, Ctx, F>>;
|
||||
|
||||
pub trait CInliningFactory<'a, Ctx: Context<'a>>:
|
||||
FactoryBase<'a, Ctx> + ImplMode<Mode = InliningMode>
|
||||
{
|
||||
fn cextension_error(&self, tail: &[u8]) -> Self::ParseError;
|
||||
|
||||
fn cideserialize<I: InCtx<'a, Ctx>>(&self, inctx: I) -> IParseResult<'a, Ctx, Self, I>;
|
||||
}
|
||||
|
||||
/// This factory should return an error on EOF.
|
||||
pub trait InliningFactory<'a, Ctx: Context<'a>>:
|
||||
FactoryBase<'a, Ctx> + ParseMode<Mode = InliningMode>
|
||||
{
|
||||
fn extension_error(&self, tail: &[u8]) -> Self::ParseError;
|
||||
|
||||
fn ideserialize<I: InCtx<'a, Ctx>>(&self, inctx: I) -> IParseResult<'a, Ctx, 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, Ctx, Self, I> {
|
||||
self.mdeserialize(inctx)
|
||||
}
|
||||
}
|
||||
|
||||
/// This factory always reads the same amount of bytes or returns error.
|
||||
pub trait FixedSizeFactory<'a, Ctx: Context<'a>>: InliningFactory<'a, Ctx> {
|
||||
/// For [`ConstSizeFactory`] this must return [`ConstSizeFactory::SIZE`].
|
||||
|
@ -1,33 +0,0 @@
|
||||
use crate::mode::*;
|
||||
|
||||
use super::*;
|
||||
|
||||
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, Ctx, F, I> {
|
||||
f.cideserialize(inctx)
|
||||
}
|
||||
|
||||
fn pmextend(
|
||||
f: &F,
|
||||
_mentionable: ExtensionSourceM<'a, Ctx, F>,
|
||||
tail: &[u8],
|
||||
) -> ExtensionResultM<'a, Ctx, F> {
|
||||
f.cextension_error(tail)
|
||||
}
|
||||
}
|
||||
|
||||
impl<A: CInliningAtomic> AtomicModeProxy for WithMode<A, InliningMode> {
|
||||
type A = A;
|
||||
|
||||
fn pma_deserialize<I: Stream>(stream: I) -> AModeResultM<Self::A, I> {
|
||||
A::ca_ideserialize(stream)
|
||||
}
|
||||
|
||||
fn pma_extend(_atomic: AExtensionSourceM<Self::A>, tail: &[u8]) -> AExtensionResultM<Self::A> {
|
||||
A::ca_extension_error(tail)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user