reorganise atomic bounds
This commit is contained in:
parent
dd8e0322e8
commit
cf5390fbec
@ -6,23 +6,23 @@ use super::*;
|
|||||||
|
|
||||||
/// Generic implementation of a [Mentionable] for [Atomic]s.
|
/// Generic implementation of a [Mentionable] for [Atomic]s.
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct AtomicObject<A: Atomic> {
|
pub struct AtomicObject<A: AtomicBase> {
|
||||||
atomic: A,
|
atomic: A,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<A: Atomic> From<A> for AtomicObject<A> {
|
impl<A: AtomicBase> From<A> for AtomicObject<A> {
|
||||||
fn from(value: A) -> Self {
|
fn from(value: A) -> Self {
|
||||||
Self { atomic: value }
|
Self { atomic: value }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<A: Atomic> AsRef<A> for AtomicObject<A> {
|
impl<A: AtomicBase> AsRef<A> for AtomicObject<A> {
|
||||||
fn as_ref(&self) -> &A {
|
fn as_ref(&self) -> &A {
|
||||||
&self.atomic
|
&self.atomic
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<A: Atomic> Deref for AtomicObject<A> {
|
impl<A: AtomicBase> Deref for AtomicObject<A> {
|
||||||
type Target = A;
|
type Target = A;
|
||||||
|
|
||||||
fn deref(&self) -> &Self::Target {
|
fn deref(&self) -> &Self::Target {
|
||||||
@ -30,7 +30,7 @@ impl<A: Atomic> Deref for AtomicObject<A> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<A: Atomic> Serializable for AtomicObject<A> {
|
impl<A: AtomicBase> Serializable for AtomicObject<A> {
|
||||||
fn serialize(&self, serializer: &mut dyn Serializer) {
|
fn serialize(&self, serializer: &mut dyn Serializer) {
|
||||||
self.atomic.serialize(serializer)
|
self.atomic.serialize(serializer)
|
||||||
}
|
}
|
||||||
@ -51,17 +51,17 @@ impl<'a, Ctx: Context<'a>, A: Atomic> Mentionable<'a, Ctx> for AtomicObject<A> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Generic implementation of a [Factory] for [Atomic]s.
|
/// Generic implementation of a [Factory] for [Atomic]s.
|
||||||
pub struct AtomicFactory<A: Atomic> {
|
pub struct AtomicFactory<A> {
|
||||||
_pd: PhantomData<A>,
|
_pd: PhantomData<A>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<A: Atomic> AtomicFactory<A> {
|
impl<A> AtomicFactory<A> {
|
||||||
fn new() -> Self {
|
fn new() -> Self {
|
||||||
AtomicFactory { _pd: PhantomData }
|
AtomicFactory { _pd: PhantomData }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<A: Atomic> Clone for AtomicFactory<A> {
|
impl<A: AtomicBase> Clone for AtomicFactory<A> {
|
||||||
fn clone(&self) -> Self {
|
fn clone(&self) -> Self {
|
||||||
Self::new()
|
Self::new()
|
||||||
}
|
}
|
||||||
@ -73,7 +73,7 @@ impl<'a, Ctx: Context<'a>, A: Atomic> FactoryBase<'a, Ctx> for AtomicFactory<A>
|
|||||||
type ParseError = A::AParseError;
|
type ParseError = A::AParseError;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<A: Atomic> ParseMode for AtomicFactory<A> {
|
impl<A> ParseMode for AtomicFactory<A> {
|
||||||
type Mode = RegularMode;
|
type Mode = RegularMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -88,7 +88,7 @@ impl<'a, Ctx: Context<'a>, A: Atomic> RegularFactory<'a, Ctx> for AtomicFactory<
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Extension trait to provide method-like utilities associated with [AtomicObject]s.
|
/// Extension trait to provide method-like utilities associated with [AtomicObject]s.
|
||||||
pub trait AtomicObjectExt: Atomic {
|
pub trait AtomicObjectExt: AtomicBase {
|
||||||
/// Shorthand for getting specific [`AtomicFactory`].
|
/// Shorthand for getting specific [`AtomicFactory`].
|
||||||
fn f() -> AtomicFactory<Self> {
|
fn f() -> AtomicFactory<Self> {
|
||||||
AtomicFactory::new()
|
AtomicFactory::new()
|
||||||
@ -99,4 +99,4 @@ pub trait AtomicObjectExt: Atomic {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<A: Atomic> AtomicObjectExt for A {}
|
impl<A: AtomicBase> AtomicObjectExt for A {}
|
||||||
|
@ -48,7 +48,7 @@ pub trait ConstSizeObject<'a, Ctx: Context<'a>>: FixedSizeObject<'a, Ctx> {
|
|||||||
pub type ADParseResult<A, D> = Result<(A, D), AParseError<A>>;
|
pub type ADParseResult<A, D> = Result<(A, D), AParseError<A>>;
|
||||||
|
|
||||||
/// Atomic analogue of [`InlineableFactory`]/[`InlineableObject`].
|
/// Atomic analogue of [`InlineableFactory`]/[`InlineableObject`].
|
||||||
pub trait InlineableAtomic: Atomic {
|
pub trait InlineableAtomic: AtomicBase {
|
||||||
fn a_extension_error(tail: &[u8]) -> Self::AParseError;
|
fn a_extension_error(tail: &[u8]) -> Self::AParseError;
|
||||||
|
|
||||||
fn a_ideserialize<D: Inlining>(inlining: D) -> ADParseResult<Self, D>;
|
fn a_ideserialize<D: Inlining>(inlining: D) -> ADParseResult<Self, D>;
|
||||||
@ -63,7 +63,9 @@ pub trait ConstSizeAtomic: InlineableAtomic {
|
|||||||
const SIZE: usize;
|
const SIZE: usize;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, Ctx: Context<'a>, A: InlineableAtomic> InlineableFactory<'a, Ctx> for AtomicFactory<A> {
|
impl<'a, Ctx: Context<'a>, A: InlineableAtomic + Atomic> InlineableFactory<'a, Ctx>
|
||||||
|
for AtomicFactory<A>
|
||||||
|
{
|
||||||
fn extension_error(&self, tail: &[u8]) -> Self::ParseError {
|
fn extension_error(&self, tail: &[u8]) -> Self::ParseError {
|
||||||
A::a_extension_error(tail)
|
A::a_extension_error(tail)
|
||||||
}
|
}
|
||||||
@ -74,13 +76,17 @@ impl<'a, Ctx: Context<'a>, A: InlineableAtomic> InlineableFactory<'a, Ctx> for A
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, Ctx: Context<'a>, A: ConstSizeAtomic> FixedSizeFactory<'a, Ctx> for AtomicFactory<A> {
|
impl<'a, Ctx: Context<'a>, A: ConstSizeAtomic + Atomic> FixedSizeFactory<'a, Ctx>
|
||||||
|
for AtomicFactory<A>
|
||||||
|
{
|
||||||
fn size(&self) -> usize {
|
fn size(&self) -> usize {
|
||||||
A::SIZE
|
A::SIZE
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, Ctx: Context<'a>, A: ConstSizeAtomic> ConstSizeFactory<'a, Ctx> for AtomicFactory<A> {
|
impl<'a, Ctx: Context<'a>, A: ConstSizeAtomic + Atomic> ConstSizeFactory<'a, Ctx>
|
||||||
|
for AtomicFactory<A>
|
||||||
|
{
|
||||||
const SIZE: usize = A::SIZE;
|
const SIZE: usize = A::SIZE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user