A/a_ prefixes for Atomic
to allow for Factory parsing later
This commit is contained in:
parent
abadb16cbf
commit
73535fcf7d
@ -15,32 +15,32 @@ use super::*;
|
|||||||
/// while limiting [`Mentionable::points`] (and corresponding [`Mentionable::topology`]) to an empty sequence.
|
/// while limiting [`Mentionable::points`] (and corresponding [`Mentionable::topology`]) to an empty sequence.
|
||||||
pub trait Atomic: 'static + Send + Sync + Send + Clone + Serializable {
|
pub trait Atomic: 'static + Send + Sync + Send + Clone + Serializable {
|
||||||
/// Equivalent of [`Factory::ParseError`].
|
/// Equivalent of [`Factory::ParseError`].
|
||||||
type ParseError: Error;
|
type AParseError: Error;
|
||||||
/// Static equivalent of [`Factory::deserialize`].
|
/// Static equivalent of [`Factory::deserialize`].
|
||||||
fn deserialize(deserializer: &mut dyn Deserializer) -> Result<Self, Self::ParseError>;
|
fn a_deserialize(deserializer: &mut dyn Deserializer) -> Result<Self, Self::AParseError>;
|
||||||
/// Static equivalent of [`Factory::unexpected_tail`].
|
/// Static equivalent of [`Factory::unexpected_tail`].
|
||||||
fn unexpected_tail(tail: &[u8]) -> Self::ParseError;
|
fn a_unexpected_tail(tail: &[u8]) -> Self::AParseError;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn _parse_slice<A: Atomic>(slice: &[u8]) -> Result<A, A::ParseError> {
|
fn _parse_slice<A: Atomic>(slice: &[u8]) -> Result<A, A::AParseError> {
|
||||||
let mut deserializer = SliceDeserializer::from(slice);
|
let mut deserializer = SliceDeserializer::from(slice);
|
||||||
let mentionable = A::deserialize(&mut deserializer)?;
|
let mentionable = A::a_deserialize(&mut deserializer)?;
|
||||||
let tail = deserializer.read_all();
|
let tail = deserializer.read_all();
|
||||||
if tail.is_empty() {
|
if tail.is_empty() {
|
||||||
Ok(mentionable)
|
Ok(mentionable)
|
||||||
} else {
|
} else {
|
||||||
Err(A::unexpected_tail(tail))
|
Err(A::a_unexpected_tail(tail))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Extension trait to provide method-like utilities associated with [Atomic]s.
|
/// Extension trait to provide method-like utilities associated with [Atomic]s.
|
||||||
pub trait ExtAtomic: Atomic {
|
pub trait ExtAtomic: Atomic {
|
||||||
/// Static equivalent of [`ExtFactory::parse_slice`].
|
/// Static equivalent of [`ExtFactory::parse_slice`].
|
||||||
fn parse_slice(slice: &[u8]) -> Result<Self, Self::ParseError>;
|
fn parse_slice(slice: &[u8]) -> Result<Self, Self::AParseError>;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<A: Atomic> ExtAtomic for A {
|
impl<A: Atomic> ExtAtomic for A {
|
||||||
fn parse_slice(slice: &[u8]) -> Result<Self, Self::ParseError> {
|
fn parse_slice(slice: &[u8]) -> Result<Self, Self::AParseError> {
|
||||||
_parse_slice(slice)
|
_parse_slice(slice)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -69,7 +69,7 @@ impl<A: Atomic> Clone for AtomicFactory<A> {
|
|||||||
impl<'a, Ctx: 'a + Context, A: Atomic> Factory<'a, Ctx> for AtomicFactory<A> {
|
impl<'a, Ctx: 'a + Context, A: Atomic> Factory<'a, Ctx> for AtomicFactory<A> {
|
||||||
type Mtbl = AtomicObject<A>;
|
type Mtbl = AtomicObject<A>;
|
||||||
|
|
||||||
type ParseError = A::ParseError;
|
type ParseError = A::AParseError;
|
||||||
|
|
||||||
fn deserialize(
|
fn deserialize(
|
||||||
&self,
|
&self,
|
||||||
@ -77,11 +77,11 @@ impl<'a, Ctx: 'a + Context, A: Atomic> Factory<'a, Ctx> for AtomicFactory<A> {
|
|||||||
_resolver: Rc<dyn Resolver<'a, Ctx>>,
|
_resolver: Rc<dyn Resolver<'a, Ctx>>,
|
||||||
_addresses: &mut Addresses,
|
_addresses: &mut Addresses,
|
||||||
) -> ParseResult<'a, Ctx, Self> {
|
) -> ParseResult<'a, Ctx, Self> {
|
||||||
Ok(A::deserialize(deserializer)?.into())
|
Ok(A::a_deserialize(deserializer)?.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn unexpected_tail(&self, tail: &[u8]) -> Self::ParseError {
|
fn unexpected_tail(&self, tail: &[u8]) -> Self::ParseError {
|
||||||
A::unexpected_tail(tail)
|
A::a_unexpected_tail(tail)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,9 +44,9 @@ impl From<&[u8]> for BooleanParseError {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Atomic for bool {
|
impl Atomic for bool {
|
||||||
type ParseError = BooleanParseError;
|
type AParseError = BooleanParseError;
|
||||||
|
|
||||||
fn deserialize(deserializer: &mut dyn Deserializer) -> Result<Self, Self::ParseError> {
|
fn a_deserialize(deserializer: &mut dyn Deserializer) -> Result<Self, Self::AParseError> {
|
||||||
let byte = deserializer.read_n_const::<1>()?;
|
let byte = deserializer.read_n_const::<1>()?;
|
||||||
match byte[0] {
|
match byte[0] {
|
||||||
0 => Ok(false),
|
0 => Ok(false),
|
||||||
@ -55,7 +55,7 @@ impl Atomic for bool {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn unexpected_tail(tail: &[u8]) -> Self::ParseError {
|
fn a_unexpected_tail(tail: &[u8]) -> Self::AParseError {
|
||||||
BooleanParseError::ExtraData(tail.len())
|
BooleanParseError::ExtraData(tail.len())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -29,13 +29,13 @@ impl Serializable for Plain {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Atomic for Plain {
|
impl Atomic for Plain {
|
||||||
type ParseError = PlainParseError;
|
type AParseError = PlainParseError;
|
||||||
|
|
||||||
fn deserialize(deserializer: &mut dyn Deserializer) -> Result<Self, Self::ParseError> {
|
fn a_deserialize(deserializer: &mut dyn Deserializer) -> Result<Self, Self::AParseError> {
|
||||||
Ok(Plain::from_slice(deserializer.read_all()))
|
Ok(Plain::from_slice(deserializer.read_all()))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn unexpected_tail(tail: &[u8]) -> Self::ParseError {
|
fn a_unexpected_tail(tail: &[u8]) -> Self::AParseError {
|
||||||
panic!(
|
panic!(
|
||||||
"Plain must use read_all, therefore there must not be any extra tail (received {} bytes).",
|
"Plain must use read_all, therefore there must not be any extra tail (received {} bytes).",
|
||||||
tail.len()
|
tail.len()
|
||||||
|
@ -183,7 +183,7 @@ impl<'a, Ctx: 'a + Context, F: Factory<'a, Ctx>> Factory<'a, Ctx> for RBFactory<
|
|||||||
resolver: std::rc::Rc<dyn Resolver<'a, Ctx>>,
|
resolver: std::rc::Rc<dyn Resolver<'a, Ctx>>,
|
||||||
addresses: &mut Addresses,
|
addresses: &mut Addresses,
|
||||||
) -> ParseResult<'a, Ctx, Self> {
|
) -> ParseResult<'a, Ctx, Self> {
|
||||||
let rb = RB::deserialize(deserializer)?;
|
let rb = RB::a_deserialize(deserializer)?;
|
||||||
Ok(match rb {
|
Ok(match rb {
|
||||||
R => RBNode::R(
|
R => RBNode::R(
|
||||||
RFactory {
|
RFactory {
|
||||||
|
Loading…
Reference in New Issue
Block a user