Atomic: ParseMode
This commit is contained in:
parent
cf5390fbec
commit
53266188a3
@ -12,6 +12,8 @@ use std::marker::PhantomData;
|
|||||||
|
|
||||||
use crate::rcore::*;
|
use crate::rcore::*;
|
||||||
|
|
||||||
|
pub use self::modes::{AtomicProxy, RegularAtomic};
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
pub type AParseError<A> = <A as AtomicBase>::AParseError;
|
pub type AParseError<A> = <A as AtomicBase>::AParseError;
|
||||||
@ -26,7 +28,7 @@ pub trait AtomicBase: 'static + Send + Sync + Send + Clone + Serializable {
|
|||||||
type AParseError: Error;
|
type AParseError: Error;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait Atomic: AtomicBase {
|
pub trait Atomic: AtomicBase + ParseMode {
|
||||||
/// Static equivalent of [`Factory::deserialize`].
|
/// Static equivalent of [`Factory::deserialize`].
|
||||||
fn a_deserialize(inlining: impl Inlining) -> AParseResult<Self>;
|
fn a_deserialize(inlining: impl Inlining) -> AParseResult<Self>;
|
||||||
/// Static equivalent of [`Factory::extend`].
|
/// Static equivalent of [`Factory::extend`].
|
||||||
|
@ -38,12 +38,16 @@ impl<const N: usize> AtomicBase for [u8; N] {
|
|||||||
type AParseError = ArrayParseError;
|
type AParseError = ArrayParseError;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<const N: usize> Atomic for [u8; N] {
|
impl<const N: usize> ParseMode for [u8; N] {
|
||||||
fn a_deserialize(inlining: impl Inlining) -> AParseResult<Self> {
|
type Mode = RegularMode;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<const N: usize> RegularAtomic for [u8; N] {
|
||||||
|
fn ra_deserialize(inlining: impl Inlining) -> AParseResult<Self> {
|
||||||
Self::a_ideserialize(inlining).seal()
|
Self::a_ideserialize(inlining).seal()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn a_extend(self, tail: &[u8]) -> AParseResult<Self> {
|
fn ra_extend(self, tail: &[u8]) -> AParseResult<Self> {
|
||||||
Err(Self::a_extension_error(tail))
|
Err(Self::a_extension_error(tail))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -38,12 +38,16 @@ impl AtomicBase for u64 {
|
|||||||
type AParseError = IntParseError;
|
type AParseError = IntParseError;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Atomic for u64 {
|
impl ParseMode for u64 {
|
||||||
fn a_deserialize(inlining: impl Inlining) -> AParseResult<Self> {
|
type Mode = RegularMode;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl RegularAtomic for u64 {
|
||||||
|
fn ra_deserialize(inlining: impl Inlining) -> AParseResult<Self> {
|
||||||
Self::a_ideserialize(inlining).seal()
|
Self::a_ideserialize(inlining).seal()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn a_extend(self, tail: &[u8]) -> AParseResult<Self> {
|
fn ra_extend(self, tail: &[u8]) -> AParseResult<Self> {
|
||||||
Err(Self::a_extension_error(tail))
|
Err(Self::a_extension_error(tail))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -45,12 +45,16 @@ impl AtomicBase for bool {
|
|||||||
type AParseError = BooleanParseError;
|
type AParseError = BooleanParseError;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Atomic for bool {
|
impl ParseMode for bool {
|
||||||
fn a_deserialize(inlining: impl Inlining) -> AParseResult<Self> {
|
type Mode = RegularMode;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl RegularAtomic for bool {
|
||||||
|
fn ra_deserialize(inlining: impl Inlining) -> AParseResult<Self> {
|
||||||
Self::a_ideserialize(inlining).seal()
|
Self::a_ideserialize(inlining).seal()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn a_extend(self, tail: &[u8]) -> AParseResult<Self> {
|
fn ra_extend(self, tail: &[u8]) -> AParseResult<Self> {
|
||||||
Err(Self::a_extension_error(tail))
|
Err(Self::a_extension_error(tail))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -32,12 +32,16 @@ impl AtomicBase for Plain {
|
|||||||
type AParseError = PlainParseError;
|
type AParseError = PlainParseError;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Atomic for Plain {
|
impl ParseMode for Plain {
|
||||||
fn a_deserialize(inlining: impl Inlining) -> AParseResult<Self> {
|
type Mode = RegularMode;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl RegularAtomic for Plain {
|
||||||
|
fn ra_deserialize(inlining: impl Inlining) -> AParseResult<Self> {
|
||||||
Ok(inlining.iread_all(Plain::from_slice))
|
Ok(inlining.iread_all(Plain::from_slice))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn a_extend(mut self, tail: &[u8]) -> AParseResult<Self> {
|
fn ra_extend(mut self, tail: &[u8]) -> AParseResult<Self> {
|
||||||
self.data.extend_from_slice(tail);
|
self.data.extend_from_slice(tail);
|
||||||
Ok(self)
|
Ok(self)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user