ParseResult in extend signature

This commit is contained in:
AF 2023-06-19 12:57:12 +00:00
parent 14f5c6a13f
commit 4b44733845
8 changed files with 9 additions and 29 deletions

View File

@ -76,7 +76,7 @@ pub trait Factory<'a, Ctx: Context<'a>>: 'a + Send + Sync + Clone {
addresses: &mut Addresses,
) -> ParseResult<'a, Ctx, Self>;
/// Called by finite stream parsers if there's any data left.
fn extend(&self, mentionable: Self::Mtbl, tail: &[u8]) -> Result<Self::Mtbl, Self::ParseError>;
fn extend(&self, mentionable: Self::Mtbl, tail: &[u8]) -> ParseResult<'a, Ctx, Self>;
}
pub type Mtbl<'a, Ctx, F> = <F as Factory<'a, Ctx>>::Mtbl;

View File

@ -81,7 +81,7 @@ impl<'a, Ctx: Context<'a>, A: Atomic> Factory<'a, Ctx> for AtomicFactory<A> {
Ok(A::a_deserialize(deserializer)?.into())
}
fn extend(&self, mentionable: Self::Mtbl, tail: &[u8]) -> Result<Self::Mtbl, Self::ParseError> {
fn extend(&self, mentionable: Self::Mtbl, tail: &[u8]) -> ParseResult<'a, Ctx, Self> {
Ok(A::a_extend(mentionable.atomic, tail)?.into())
}
}

View File

@ -102,11 +102,7 @@ impl<'a, Ctx: Context<'a>, F: Factory<'a, Ctx>> Factory<'a, Ctx> for StackNodeFa
Ok(StackNode { rest, element })
}
fn extend(
&self,
mut mentionable: Self::Mtbl,
tail: &[u8],
) -> Result<Self::Mtbl, Self::ParseError> {
fn extend(&self, mut mentionable: Self::Mtbl, tail: &[u8]) -> ParseResult<'a, Ctx, Self> {
mentionable.element = self
.element_factory
.extend(mentionable.element, tail)

View File

@ -151,11 +151,7 @@ impl<'a, Ctx: Context<'a>, F: Factory<'a, Ctx>> Factory<'a, Ctx> for NodeFactory
Ok(Node { l, r, key })
}
fn extend(
&self,
mut mentionable: Self::Mtbl,
tail: &[u8],
) -> Result<Self::Mtbl, Self::ParseError> {
fn extend(&self, mut mentionable: Self::Mtbl, tail: &[u8]) -> ParseResult<'a, Ctx, Self> {
mentionable.key = self
.0
.extend(mentionable.key, tail)
@ -182,11 +178,7 @@ impl<'a, Ctx: Context<'a>, F: Factory<'a, Ctx>> Factory<'a, Ctx> for TreeFactory
Ok(tree)
}
fn extend(
&self,
mut mentionable: Self::Mtbl,
tail: &[u8],
) -> Result<Self::Mtbl, Self::ParseError> {
fn extend(&self, mut mentionable: Self::Mtbl, tail: &[u8]) -> ParseResult<'a, Ctx, Self> {
mentionable.height = u64::a_extend(mentionable.height, tail)?;
mentionable.validate_height()?;
Ok(mentionable)

View File

@ -151,7 +151,7 @@ impl<'a, Ctx: Context<'a>, SP: StaticPair<'a, Ctx>> Factory<'a, Ctx>
})
}
fn extend(&self, mentionable: Self::Mtbl, tail: &[u8]) -> Result<Self::Mtbl, Self::ParseError> {
fn extend(&self, mentionable: Self::Mtbl, tail: &[u8]) -> ParseResult<'a, Ctx, Self> {
let (_, fb) = SP::factories(&self.factory_data);
let (a, b) = mentionable.pair.into_elements();
match fb.extend(b, tail) {

View File

@ -70,11 +70,7 @@ impl<'a, Ctx: Context<'a>, F: Factory<'a, Ctx>> Factory<'a, Ctx> for NullableFac
})
}
fn extend(
&self,
_mentionable: Self::Mtbl,
tail: &[u8],
) -> Result<Self::Mtbl, Self::ParseError> {
fn extend(&self, _mentionable: Self::Mtbl, tail: &[u8]) -> ParseResult<'a, Ctx, Self> {
Err(PointParseError::WrongLength(HASH_SIZE + tail.len()))
}
}

View File

@ -76,11 +76,7 @@ impl<'a, Ctx: Context<'a>, F: Factory<'a, Ctx>> Factory<'a, Ctx> for PointFactor
Ok(addresses.next_point(deserializer, resolver, self.factory.clone())?)
}
fn extend(
&self,
_mentionable: Self::Mtbl,
tail: &[u8],
) -> Result<Self::Mtbl, Self::ParseError> {
fn extend(&self, _mentionable: Self::Mtbl, tail: &[u8]) -> ParseResult<'a, Ctx, Self> {
Err(PointParseError::WrongLength(HASH_SIZE + tail.len()))
}
}

View File

@ -107,7 +107,7 @@ impl<'a, Ctx: Context<'a>> Factory<'a, Ctx> for TypelessFactory<'a, Ctx> {
}
}
fn extend(&self, mentionable: Self::Mtbl, tail: &[u8]) -> Result<Self::Mtbl, Self::ParseError> {
fn extend(&self, mentionable: Self::Mtbl, tail: &[u8]) -> ParseResult<'a, Ctx, Self> {
self.t_extend.xt(mentionable, tail)
}
}