QInliningFactory
This commit is contained in:
parent
c9e65ca690
commit
aa914d0c89
@ -205,16 +205,16 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, Ctx: Context<'a>, F: Factory<'a, Ctx> + InliningFactory<'a, Ctx>> InliningFactory<'a, Ctx>
|
impl<'a, Ctx: Context<'a>, F: Factory<'a, Ctx> + InliningFactory<'a, Ctx>> QInliningFactory<'a, Ctx>
|
||||||
for StackNodeFactory<F>
|
for StackNodeFactory<F>
|
||||||
where
|
where
|
||||||
F::Mtbl: MentionableTop<'a, Ctx>,
|
F::Mtbl: MentionableTop<'a, Ctx>,
|
||||||
{
|
{
|
||||||
fn extension_error(&self, tail: &[u8]) -> Self::ParseError {
|
fn qextension_error(&self, tail: &[u8]) -> Self::ParseError {
|
||||||
StackParseError::Element(self.element_factory.extension_error(tail))
|
StackParseError::Element(self.element_factory.extension_error(tail))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn ideserialize<I: InCtx<'a, Ctx>>(&self, inctx: I) -> IParseResult<'a, Ctx, Self, I> {
|
fn qideserialize<I: InCtx<'a, Ctx>>(&self, inctx: I) -> IParseResult<'a, Ctx, Self, I> {
|
||||||
let (rest, inctx) = self.parse_point(inctx)?;
|
let (rest, inctx) = self.parse_point(inctx)?;
|
||||||
let (element, inctx) = self
|
let (element, inctx) = self
|
||||||
.element_factory
|
.element_factory
|
||||||
|
@ -172,12 +172,12 @@ impl<F> ImplMode for TreeFactory<F> {
|
|||||||
type Mode = InliningMode;
|
type Mode = InliningMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, Ctx: Context<'a>, F: FactoryParse<'a, Ctx>> InliningFactory<'a, Ctx> for TreeFactory<F> {
|
impl<'a, Ctx: Context<'a>, F: FactoryParse<'a, Ctx>> QInliningFactory<'a, Ctx> for TreeFactory<F> {
|
||||||
fn extension_error(&self, tail: &[u8]) -> Self::ParseError {
|
fn qextension_error(&self, tail: &[u8]) -> Self::ParseError {
|
||||||
u64::a_extension_error(tail).into()
|
u64::a_extension_error(tail).into()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn ideserialize<I: InCtx<'a, Ctx>>(&self, inctx: I) -> IParseResult<'a, Ctx, Self, I> {
|
fn qideserialize<I: InCtx<'a, Ctx>>(&self, inctx: I) -> IParseResult<'a, Ctx, Self, I> {
|
||||||
let (node, inctx) = self.0.ideserialize(inctx)?;
|
let (node, inctx) = self.0.ideserialize(inctx)?;
|
||||||
let (height, inctx) = u64::a_ideserialize(inctx)?;
|
let (height, inctx) = u64::a_ideserialize(inctx)?;
|
||||||
let tree = Tree { node, height };
|
let tree = Tree { node, height };
|
||||||
|
@ -14,6 +14,14 @@ pub use self::modes::InliningMode;
|
|||||||
|
|
||||||
pub type IParseResult<'a, Ctx, F, I> = Result<(Mtbl<'a, Ctx, F>, I), ParseError<'a, Ctx, F>>;
|
pub type IParseResult<'a, Ctx, F, I> = Result<(Mtbl<'a, Ctx, F>, I), ParseError<'a, Ctx, F>>;
|
||||||
|
|
||||||
|
pub trait QInliningFactory<'a, Ctx: Context<'a>>:
|
||||||
|
FactoryBase<'a, Ctx> + ImplMode<Mode = InliningMode>
|
||||||
|
{
|
||||||
|
fn qextension_error(&self, tail: &[u8]) -> Self::ParseError;
|
||||||
|
|
||||||
|
fn qideserialize<I: InCtx<'a, Ctx>>(&self, inctx: I) -> IParseResult<'a, Ctx, Self, I>;
|
||||||
|
}
|
||||||
|
|
||||||
/// This factory should return an error on EOF.
|
/// This factory should return an error on EOF.
|
||||||
pub trait InliningFactory<'a, Ctx: Context<'a>>:
|
pub trait InliningFactory<'a, Ctx: Context<'a>>:
|
||||||
FactoryBase<'a, Ctx> + ParseMode<Mode = InliningMode>
|
FactoryBase<'a, Ctx> + ParseMode<Mode = InliningMode>
|
||||||
@ -23,6 +31,18 @@ pub trait InliningFactory<'a, Ctx: Context<'a>>:
|
|||||||
fn ideserialize<I: InCtx<'a, Ctx>>(&self, inctx: I) -> IParseResult<'a, Ctx, Self, I>;
|
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.
|
/// This factory always reads the same amount of bytes or returns error.
|
||||||
pub trait FixedSizeFactory<'a, Ctx: Context<'a>>: InliningFactory<'a, Ctx> {
|
pub trait FixedSizeFactory<'a, Ctx: Context<'a>>: InliningFactory<'a, Ctx> {
|
||||||
/// For [`ConstSizeFactory`] this must return [`ConstSizeFactory::SIZE`].
|
/// For [`ConstSizeFactory`] this must return [`ConstSizeFactory::SIZE`].
|
||||||
@ -84,24 +104,17 @@ pub trait ConstSizeAtomic: InliningAtomic {
|
|||||||
const SIZE: usize;
|
const SIZE: usize;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, Ctx: Context<'a>, A: InliningAtomic> InliningFactory<'a, Ctx> for AtomicFactory<A> {
|
impl<'a, Ctx: Context<'a>, A: ConstSizeAtomic + AtomicModeParse> FixedSizeFactory<'a, Ctx>
|
||||||
fn extension_error(&self, tail: &[u8]) -> Self::ParseError {
|
for AtomicFactory<A>
|
||||||
A::a_extension_error(tail)
|
{
|
||||||
}
|
|
||||||
|
|
||||||
fn ideserialize<I: InCtx<'a, Ctx>>(&self, inctx: I) -> IParseResult<'a, Ctx, Self, I> {
|
|
||||||
let (a, inctx) = A::a_ideserialize(inctx)?;
|
|
||||||
Ok((a.into(), inctx))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a, Ctx: Context<'a>, A: ConstSizeAtomic> FixedSizeFactory<'a, Ctx> for AtomicFactory<A> {
|
|
||||||
fn size(&self) -> usize {
|
fn size(&self) -> usize {
|
||||||
A::SIZE
|
A::SIZE
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, Ctx: Context<'a>, A: ConstSizeAtomic> ConstSizeFactory<'a, Ctx> for AtomicFactory<A> {
|
impl<'a, Ctx: Context<'a>, A: ConstSizeAtomic + AtomicModeParse> ConstSizeFactory<'a, Ctx>
|
||||||
|
for AtomicFactory<A>
|
||||||
|
{
|
||||||
const SIZE: usize = A::SIZE;
|
const SIZE: usize = A::SIZE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,7 +55,7 @@ impl Mode for InliningMode {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, Ctx: Context<'a>, F: InliningFactory<'a, Ctx>> FactoryModeProxy<'a, Ctx>
|
impl<'a, Ctx: Context<'a>, F: QInliningFactory<'a, Ctx>> FactoryModeProxy<'a, Ctx>
|
||||||
for WithMode<F, InliningMode>
|
for WithMode<F, InliningMode>
|
||||||
{
|
{
|
||||||
type F = F;
|
type F = F;
|
||||||
|
@ -172,17 +172,17 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, Ctx: Context<'a>, SP: StaticPair<'a, Ctx>> InliningFactory<'a, Ctx>
|
impl<'a, Ctx: Context<'a>, SP: StaticPair<'a, Ctx>> QInliningFactory<'a, Ctx>
|
||||||
for StaticPairFactory<'a, Ctx, SP>
|
for StaticPairFactory<'a, Ctx, SP>
|
||||||
where
|
where
|
||||||
SP::FB: InliningFactory<'a, Ctx>,
|
SP::FB: InliningFactory<'a, Ctx>,
|
||||||
{
|
{
|
||||||
fn extension_error(&self, tail: &[u8]) -> Self::ParseError {
|
fn qextension_error(&self, tail: &[u8]) -> Self::ParseError {
|
||||||
let (_, fb) = SP::factories(&self.factory_data);
|
let (_, fb) = SP::factories(&self.factory_data);
|
||||||
SP::from_error_b(&self.factory_data, fb.extension_error(tail))
|
SP::from_error_b(&self.factory_data, fb.extension_error(tail))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn ideserialize<I: InCtx<'a, Ctx>>(&self, inctx: I) -> IParseResult<'a, Ctx, Self, I> {
|
fn qideserialize<I: InCtx<'a, Ctx>>(&self, inctx: I) -> IParseResult<'a, Ctx, Self, I> {
|
||||||
let (fa, fb) = SP::factories(&self.factory_data);
|
let (fa, fb) = SP::factories(&self.factory_data);
|
||||||
let (a, inctx) = fa
|
let (a, inctx) = fa
|
||||||
.ideserialize(inctx)
|
.ideserialize(inctx)
|
||||||
|
@ -107,14 +107,14 @@ impl<'a, Ctx: Context<'a>, A: MentionableBase<'a, Ctx>> Clone for Nullable<'a, C
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, Ctx: Context<'a>, F: FactoryBase<'a, Ctx>> InliningFactory<'a, Ctx>
|
impl<'a, Ctx: Context<'a>, F: FactoryBase<'a, Ctx>> QInliningFactory<'a, Ctx>
|
||||||
for NullableFactory<F>
|
for NullableFactory<F>
|
||||||
{
|
{
|
||||||
fn extension_error(&self, tail: &[u8]) -> Self::ParseError {
|
fn qextension_error(&self, tail: &[u8]) -> Self::ParseError {
|
||||||
PointParseError::WrongLength(HASH_SIZE + tail.len())
|
PointParseError::WrongLength(HASH_SIZE + tail.len())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn ideserialize<I: InCtx<'a, Ctx>>(&self, inctx: I) -> IParseResult<'a, Ctx, Self, I> {
|
fn qideserialize<I: InCtx<'a, Ctx>>(&self, inctx: I) -> IParseResult<'a, Ctx, Self, I> {
|
||||||
let factory = self.factory.clone();
|
let factory = self.factory.clone();
|
||||||
let (address, inctx) = inctx.icnext_address(|slice| PointParseError::from(slice))?;
|
let (address, inctx) = inctx.icnext_address(|slice| PointParseError::from(slice))?;
|
||||||
Ok((
|
Ok((
|
||||||
|
@ -79,16 +79,16 @@ impl<'a, Ctx: Context<'a>, F: FactoryBase<'a, Ctx>> FactoryBase<'a, Ctx> for Poi
|
|||||||
type ParseError = PointParseError;
|
type ParseError = PointParseError;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<F> ParseMode for PointFactory<F> {
|
impl<F> ImplMode for PointFactory<F> {
|
||||||
type Mode = InliningMode;
|
type Mode = InliningMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, Ctx: Context<'a>, F: FactoryBase<'a, Ctx>> InliningFactory<'a, Ctx> for PointFactory<F> {
|
impl<'a, Ctx: Context<'a>, F: FactoryBase<'a, Ctx>> QInliningFactory<'a, Ctx> for PointFactory<F> {
|
||||||
fn extension_error(&self, tail: &[u8]) -> Self::ParseError {
|
fn qextension_error(&self, tail: &[u8]) -> Self::ParseError {
|
||||||
PointParseError::WrongLength(HASH_SIZE + tail.len())
|
PointParseError::WrongLength(HASH_SIZE + tail.len())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn ideserialize<I: InCtx<'a, Ctx>>(&self, inctx: I) -> IParseResult<'a, Ctx, Self, I> {
|
fn qideserialize<I: InCtx<'a, Ctx>>(&self, inctx: I) -> IParseResult<'a, Ctx, Self, I> {
|
||||||
inctx.icnext_point(self.inner(), |slice| PointParseError::from(slice))
|
inctx.icnext_point(self.inner(), |slice| PointParseError::from(slice))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user