49 lines
1.6 KiB
Rust
49 lines
1.6 KiB
Rust
//! This module allows to describe a primitive subset of [Mentionable] types, [Atomic]s,
|
|
//! simple static types, which are completely [Context]-independent.
|
|
|
|
pub mod atomic_object;
|
|
pub mod au64;
|
|
pub mod boolean;
|
|
pub mod plain;
|
|
|
|
use std::marker::PhantomData;
|
|
|
|
use crate::rcore::*;
|
|
|
|
use super::*;
|
|
|
|
/// This trait combines functionality of [`Mentionable`] and [`Factory`],
|
|
/// while limiting [`Mentionable::points_typed`] (and corresponding [`Mentionable::topology`])
|
|
/// to an empty sequence.
|
|
pub trait Atomic: 'static + Send + Sync + Send + Clone + Serializable {
|
|
/// Equivalent of [`Factory::ParseError`].
|
|
type AParseError: Error;
|
|
/// Static equivalent of [`Factory::deserialize`].
|
|
fn a_deserialize(deserializer: &mut dyn Deserializer) -> Result<Self, Self::AParseError>;
|
|
/// Static equivalent of [`Factory::extend`].
|
|
fn a_extend(self, tail: &[u8]) -> Result<Self, Self::AParseError>;
|
|
}
|
|
|
|
fn _parse_slice<A: Atomic>(slice: &[u8]) -> Result<A, A::AParseError> {
|
|
let mut deserializer = SliceDeserializer::from(slice);
|
|
let atomic = A::a_deserialize(&mut deserializer)?;
|
|
let tail = deserializer.read_all();
|
|
if tail.is_empty() {
|
|
Ok(atomic)
|
|
} else {
|
|
A::a_extend(atomic, tail)
|
|
}
|
|
}
|
|
|
|
/// Extension trait to provide method-like utilities associated with [Atomic]s.
|
|
pub trait ExtAtomic: Atomic {
|
|
/// Static equivalent of [`ExtFactory::parse_slice`].
|
|
fn parse_slice(slice: &[u8]) -> Result<Self, Self::AParseError>;
|
|
}
|
|
|
|
impl<A: Atomic> ExtAtomic for A {
|
|
fn parse_slice(slice: &[u8]) -> Result<Self, Self::AParseError> {
|
|
_parse_slice(slice)
|
|
}
|
|
}
|