parent
4b44733845
commit
2683f1d5ea
@ -42,7 +42,13 @@ impl Atomic for u64 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn a_extend(self, tail: &[u8]) -> Result<Self, Self::AParseError> {
|
fn a_extend(self, tail: &[u8]) -> Result<Self, Self::AParseError> {
|
||||||
Err(IntParseError::ExtraData(tail.len()))
|
Err(Self::a_extension_error(tail))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl InlineableAtomic for u64 {
|
||||||
|
fn a_extension_error(tail: &[u8]) -> Self::AParseError {
|
||||||
|
IntParseError::ExtraData(tail.len())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,7 +54,13 @@ impl Atomic for bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn a_extend(self, tail: &[u8]) -> Result<Self, Self::AParseError> {
|
fn a_extend(self, tail: &[u8]) -> Result<Self, Self::AParseError> {
|
||||||
Err(BooleanParseError::ExtraData(tail.len()))
|
Err(Self::a_extension_error(tail))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl InlineableAtomic for bool {
|
||||||
|
fn a_extension_error(tail: &[u8]) -> Self::AParseError {
|
||||||
|
BooleanParseError::ExtraData(tail.len())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -181,6 +181,9 @@ impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx> + Clone> ExtStackClone<'a, Ct
|
|||||||
impl<'a, Ctx: Context<'a>, F: InlineableFactory<'a, Ctx>> InlineableFactory<'a, Ctx>
|
impl<'a, Ctx: Context<'a>, F: InlineableFactory<'a, Ctx>> InlineableFactory<'a, Ctx>
|
||||||
for StackNodeFactory<F>
|
for StackNodeFactory<F>
|
||||||
{
|
{
|
||||||
|
fn extension_error(&self, tail: &[u8]) -> Self::ParseError {
|
||||||
|
StackParseError::Element(self.element_factory.extension_error(tail))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, Ctx: Context<'a>, F: FixedSizeFactory<'a, Ctx>> FixedSizeFactory<'a, Ctx>
|
impl<'a, Ctx: Context<'a>, F: FixedSizeFactory<'a, Ctx>> FixedSizeFactory<'a, Ctx>
|
||||||
|
@ -11,7 +11,9 @@ use super::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
/// This factory should return an error on EOF.
|
/// This factory should return an error on EOF.
|
||||||
pub trait InlineableFactory<'a, Ctx: Context<'a>>: Factory<'a, Ctx> {}
|
pub trait InlineableFactory<'a, Ctx: Context<'a>>: Factory<'a, Ctx> {
|
||||||
|
fn extension_error(&self, tail: &[u8]) -> Self::ParseError;
|
||||||
|
}
|
||||||
|
|
||||||
/// 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>>: InlineableFactory<'a, Ctx> {
|
pub trait FixedSizeFactory<'a, Ctx: Context<'a>>: InlineableFactory<'a, Ctx> {
|
||||||
@ -41,7 +43,9 @@ pub trait ConstSizeObject<'a, Ctx: Context<'a>>: FixedSizeObject<'a, Ctx> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Atomic analogue of [`InlineableFactory`]/[`InlineableObject`].
|
/// Atomic analogue of [`InlineableFactory`]/[`InlineableObject`].
|
||||||
pub trait InlineableAtomic: Atomic {}
|
pub trait InlineableAtomic: Atomic {
|
||||||
|
fn a_extension_error(tail: &[u8]) -> Self::AParseError;
|
||||||
|
}
|
||||||
|
|
||||||
/// Atomic analogue of [`ConstSizeFactory`]/[`ConstSizeObject`].
|
/// Atomic analogue of [`ConstSizeFactory`]/[`ConstSizeObject`].
|
||||||
///
|
///
|
||||||
@ -52,9 +56,11 @@ pub trait ConstSizeAtomic: InlineableAtomic {
|
|||||||
const SIZE: usize;
|
const SIZE: usize;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<A: ConstSizeAtomic> InlineableAtomic for A {}
|
impl<'a, Ctx: Context<'a>, A: InlineableAtomic> InlineableFactory<'a, Ctx> for AtomicFactory<A> {
|
||||||
|
fn extension_error(&self, tail: &[u8]) -> Self::ParseError {
|
||||||
impl<'a, Ctx: Context<'a>, A: InlineableAtomic> InlineableFactory<'a, Ctx> for AtomicFactory<A> {}
|
A::a_extension_error(tail)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<'a, Ctx: Context<'a>, A: ConstSizeAtomic> FixedSizeFactory<'a, Ctx> for AtomicFactory<A> {
|
impl<'a, Ctx: Context<'a>, A: ConstSizeAtomic> FixedSizeFactory<'a, Ctx> for AtomicFactory<A> {
|
||||||
fn size(&self) -> usize {
|
fn size(&self) -> usize {
|
||||||
@ -201,9 +207,9 @@ pub trait AlwaysFixedSize {
|
|||||||
fn _size(&self) -> usize;
|
fn _size(&self) -> usize;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, Ctx: Context<'a>, F: AlwaysFixedSize + Factory<'a, Ctx>> InlineableFactory<'a, Ctx> for F {}
|
impl<'a, Ctx: Context<'a>, F: AlwaysFixedSize + InlineableFactory<'a, Ctx>>
|
||||||
|
FixedSizeFactory<'a, Ctx> for F
|
||||||
impl<'a, Ctx: Context<'a>, F: AlwaysFixedSize + Factory<'a, Ctx>> FixedSizeFactory<'a, Ctx> for F {
|
{
|
||||||
fn size(&self) -> usize {
|
fn size(&self) -> usize {
|
||||||
self._size()
|
self._size()
|
||||||
}
|
}
|
||||||
@ -220,10 +226,18 @@ impl<F: AlwaysConstSize> AlwaysFixedSize for F {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, Ctx: Context<'a>, F: AlwaysConstSize + Factory<'a, Ctx>> ConstSizeFactory<'a, Ctx> for F {
|
impl<'a, Ctx: Context<'a>, F: AlwaysConstSize + InlineableFactory<'a, Ctx>>
|
||||||
|
ConstSizeFactory<'a, Ctx> for F
|
||||||
|
{
|
||||||
const SIZE: usize = Self::_SIZE;
|
const SIZE: usize = Self::_SIZE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'a, Ctx: Context<'a>, F: Factory<'a, Ctx>> InlineableFactory<'a, Ctx> for PointFactory<F> {
|
||||||
|
fn extension_error(&self, tail: &[u8]) -> Self::ParseError {
|
||||||
|
PointParseError::WrongLength(HASH_SIZE + tail.len())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<F> AlwaysConstSize for PointFactory<F> {
|
impl<F> AlwaysConstSize for PointFactory<F> {
|
||||||
const _SIZE: usize = HASH_SIZE;
|
const _SIZE: usize = HASH_SIZE;
|
||||||
}
|
}
|
||||||
|
@ -166,6 +166,10 @@ impl<'a, Ctx: Context<'a>, SP: StaticPair<'a, Ctx>> InlineableFactory<'a, Ctx>
|
|||||||
where
|
where
|
||||||
SP::FB: InlineableFactory<'a, Ctx>,
|
SP::FB: InlineableFactory<'a, Ctx>,
|
||||||
{
|
{
|
||||||
|
fn extension_error(&self, tail: &[u8]) -> Self::ParseError {
|
||||||
|
let (_, fb) = SP::factories(&self.factory_data);
|
||||||
|
SP::from_error_b(&self.factory_data, fb.extension_error(tail))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, Ctx: Context<'a>, SP: StaticPair<'a, Ctx>> FixedSizeFactory<'a, Ctx>
|
impl<'a, Ctx: Context<'a>, SP: StaticPair<'a, Ctx>> FixedSizeFactory<'a, Ctx>
|
||||||
|
@ -71,7 +71,7 @@ impl<'a, Ctx: Context<'a>, F: Factory<'a, Ctx>> Factory<'a, Ctx> for NullableFac
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn extend(&self, _mentionable: Self::Mtbl, tail: &[u8]) -> ParseResult<'a, Ctx, Self> {
|
fn extend(&self, _mentionable: Self::Mtbl, tail: &[u8]) -> ParseResult<'a, Ctx, Self> {
|
||||||
Err(PointParseError::WrongLength(HASH_SIZE + tail.len()))
|
Err(self.extension_error(tail))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -116,6 +116,12 @@ impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> Clone for Nullable<'a, Ctx,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'a, Ctx: Context<'a>, F: Factory<'a, Ctx>> InlineableFactory<'a, Ctx> for NullableFactory<F> {
|
||||||
|
fn extension_error(&self, tail: &[u8]) -> Self::ParseError {
|
||||||
|
PointParseError::WrongLength(HASH_SIZE + tail.len())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<F> AlwaysConstSize for NullableFactory<F> {
|
impl<F> AlwaysConstSize for NullableFactory<F> {
|
||||||
const _SIZE: usize = HASH_SIZE;
|
const _SIZE: usize = HASH_SIZE;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user