diff --git a/src/rstd/collections/stack.rs b/src/rstd/collections/stack.rs index da8cc5c..9ccaea4 100644 --- a/src/rstd/collections/stack.rs +++ b/src/rstd/collections/stack.rs @@ -167,6 +167,17 @@ impl<'a, Ctx: Context<'a>, F: InlineableFactory<'a, Ctx>> InlineableFactory<'a, fn extension_error(&self, tail: &[u8]) -> Self::ParseError { StackParseError::Element(self.element_factory.extension_error(tail)) } + + fn ideserialize>(&self, inctx: I) -> IParseResult<'a, Ctx, Self, I> { + let (rest, inctx) = NullableFactory::new(self.clone()) + .ideserialize(inctx) + .map_err(StackParseError::Point)?; + let (element, inctx) = self + .element_factory + .ideserialize(inctx) + .map_err(StackParseError::Element)?; + Ok((StackNode { rest, element }, inctx)) + } } impl<'a, Ctx: Context<'a>, F: FixedSizeFactory<'a, Ctx>> FixedSizeFactory<'a, Ctx> diff --git a/src/rstd/inlining.rs b/src/rstd/inlining.rs index 34ab4c9..62362c3 100644 --- a/src/rstd/inlining.rs +++ b/src/rstd/inlining.rs @@ -41,7 +41,15 @@ pub trait InCtx<'a, Ctx: Context<'a>>: Inlining { self, factory: A::Fctr, err: impl FnOnce(&[u8]) -> E, - ) -> Result<(Point<'a, Ctx, A>, Self), E>; + ) -> Result<(Point<'a, Ctx, A>, Self), E> { + let (point, inctx) = self.icnext_address(err)?; + Ok(( + Point::from_address(point, factory, inctx.iresolver()), + inctx, + )) + } + + fn iresolver(&self) -> Rc>; } struct InCtxT<'a: 'c, 'c, Ctx: Context<'a>> { @@ -79,16 +87,8 @@ impl<'a: 'c, 'c, Ctx: Context<'a>> InCtx<'a, Ctx> for InCtxT<'a, 'c, Ctx> { } } - fn icnext_point<'b, A: Mentionable<'a, Ctx>, E>( - self, - factory: A::Fctr, - err: impl FnOnce(&[u8]) -> E, - ) -> Result<(Point<'a, Ctx, A>, Self), E> { - let (point, inctx) = self.icnext_address(err)?; - Ok(( - Point::from_address(point, factory, inctx.dectx.resolver()), - inctx, - )) + fn iresolver(&self) -> Rc> { + self.dectx.resolver() } } @@ -98,6 +98,8 @@ pub type IParseResult<'a, Ctx, F, I> = /// This factory should return an error on EOF. pub trait InlineableFactory<'a, Ctx: Context<'a>>: Factory<'a, Ctx> { fn extension_error(&self, tail: &[u8]) -> Self::ParseError; + + fn ideserialize>(&self, inctx: I) -> IParseResult<'a, Ctx, Self, I>; } /// This factory always reads the same amount of bytes or returns error. @@ -149,6 +151,11 @@ impl<'a, Ctx: Context<'a>, A: InlineableAtomic> InlineableFactory<'a, Ctx> for A fn extension_error(&self, tail: &[u8]) -> Self::ParseError { A::a_extension_error(tail) } + + fn ideserialize>(&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 { @@ -315,6 +322,10 @@ impl<'a, Ctx: Context<'a>, F: Factory<'a, Ctx>> InlineableFactory<'a, Ctx> for P fn extension_error(&self, tail: &[u8]) -> Self::ParseError { PointParseError::WrongLength(HASH_SIZE + tail.len()) } + + fn ideserialize>(&self, inctx: I) -> IParseResult<'a, Ctx, Self, I> { + inctx.icnext_point(self.inner(), |slice| PointParseError::from(slice)) + } } impl AlwaysConstSize for PointFactory { diff --git a/src/rstd/inlining/static_pair.rs b/src/rstd/inlining/static_pair.rs index 1b289fc..81cc144 100644 --- a/src/rstd/inlining/static_pair.rs +++ b/src/rstd/inlining/static_pair.rs @@ -163,6 +163,22 @@ where let (_, fb) = SP::factories(&self.factory_data); SP::from_error_b(&self.factory_data, fb.extension_error(tail)) } + + fn ideserialize>(&self, inctx: I) -> IParseResult<'a, Ctx, Self, I> { + let (fa, fb) = SP::factories(&self.factory_data); + let (a, inctx) = fa + .ideserialize(inctx) + .map_err(|e| SP::from_error_a(&self.factory_data, e))?; + let (b, inctx) = fb + .ideserialize(inctx) + .map_err(|e| SP::from_error_b(&self.factory_data, e))?; + Ok(( + StaticPairObject { + pair: SP::from_parsed(&self.factory_data, a, b), + }, + inctx, + )) + } } impl<'a, Ctx: Context<'a>, SP: StaticPair<'a, Ctx>> FixedSizeFactory<'a, Ctx> diff --git a/src/rstd/nullable.rs b/src/rstd/nullable.rs index 26832fa..323e149 100644 --- a/src/rstd/nullable.rs +++ b/src/rstd/nullable.rs @@ -115,6 +115,19 @@ impl<'a, Ctx: Context<'a>, F: Factory<'a, Ctx>> InlineableFactory<'a, Ctx> for N fn extension_error(&self, tail: &[u8]) -> Self::ParseError { PointParseError::WrongLength(HASH_SIZE + tail.len()) } + + fn ideserialize>(&self, inctx: I) -> IParseResult<'a, Ctx, Self, I> { + let factory = self.factory.clone(); + let (address, inctx) = inctx.icnext_address(|slice| PointParseError::from(slice))?; + Ok(( + if address.point == HASH_ZEROS { + Nullable::Null(factory) + } else { + Nullable::NotNull(Point::from_address(address, factory, inctx.iresolver())) + }, + inctx, + )) + } } impl AlwaysConstSize for NullableFactory {