InlineableFactory
implying Factory
This commit is contained in:
parent
93782ba0a6
commit
5037ee3c84
@ -50,7 +50,7 @@ impl<ErrorA: Error, ErrorB: Error> Error for PairParseError<ErrorA, ErrorB> {}
|
|||||||
impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>, B: Mentionable<'a, Ctx>> StaticPair<'a, Ctx>
|
impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>, B: Mentionable<'a, Ctx>> StaticPair<'a, Ctx>
|
||||||
for Pair<A, B>
|
for Pair<A, B>
|
||||||
where
|
where
|
||||||
A::Fctr: InlineableFactory,
|
A::Fctr: InlineableFactory<'a, Ctx>,
|
||||||
{
|
{
|
||||||
type FactoryData = Pair<Self::FA, Self::FB>;
|
type FactoryData = Pair<Self::FA, Self::FB>;
|
||||||
type A = A;
|
type A = A;
|
||||||
|
@ -172,27 +172,27 @@ impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> ExtStack<'a, Ctx, A> for Sta
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> InlineableFactory
|
impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> InlineableFactory<'a, Ctx>
|
||||||
for StackNodeFactory<'a, Ctx, A>
|
for StackNodeFactory<'a, Ctx, A>
|
||||||
where
|
where
|
||||||
A::Fctr: InlineableFactory,
|
A::Fctr: InlineableFactory<'a, Ctx>,
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> FixedSizeFactory
|
impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> FixedSizeFactory<'a, Ctx>
|
||||||
for StackNodeFactory<'a, Ctx, A>
|
for StackNodeFactory<'a, Ctx, A>
|
||||||
where
|
where
|
||||||
A::Fctr: FixedSizeFactory,
|
A::Fctr: FixedSizeFactory<'a, Ctx>,
|
||||||
{
|
{
|
||||||
fn size(&self) -> usize {
|
fn size(&self) -> usize {
|
||||||
Stack::<'a, Ctx, A>::SIZE + self.element_factory.size()
|
Stack::<'a, Ctx, A>::SIZE + self.element_factory.size()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> ConstSizeFactory
|
impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> ConstSizeFactory<'a, Ctx>
|
||||||
for StackNodeFactory<'a, Ctx, A>
|
for StackNodeFactory<'a, Ctx, A>
|
||||||
where
|
where
|
||||||
A::Fctr: ConstSizeFactory,
|
A::Fctr: ConstSizeFactory<'a, Ctx>,
|
||||||
{
|
{
|
||||||
const SIZE: usize = Stack::<'a, Ctx, A>::SIZE + A::Fctr::SIZE;
|
const SIZE: usize = Stack::<'a, Ctx, A>::SIZE + A::Fctr::SIZE;
|
||||||
}
|
}
|
||||||
|
@ -11,16 +11,16 @@ use super::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
/// This factory should return an error on EOF.
|
/// This factory should return an error on EOF.
|
||||||
pub trait InlineableFactory {}
|
pub trait InlineableFactory<'a, Ctx: Context<'a>>: Factory<'a, Ctx> {}
|
||||||
|
|
||||||
/// 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: InlineableFactory {
|
pub trait FixedSizeFactory<'a, Ctx: Context<'a>>: InlineableFactory<'a, Ctx> {
|
||||||
/// For [`ConstSizeFactory`] this must return [`ConstSizeFactory::SIZE`].
|
/// For [`ConstSizeFactory`] this must return [`ConstSizeFactory::SIZE`].
|
||||||
fn size(&self) -> usize;
|
fn size(&self) -> usize;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Compile-time analogue of [`FixedSizeFactory`].
|
/// Compile-time analogue of [`FixedSizeFactory`].
|
||||||
pub trait ConstSizeFactory: FixedSizeFactory {
|
pub trait ConstSizeFactory<'a, Ctx: Context<'a>>: FixedSizeFactory<'a, Ctx> {
|
||||||
/// Must be equal to [`FixedSizeFactory::size()`].
|
/// Must be equal to [`FixedSizeFactory::size()`].
|
||||||
const SIZE: usize;
|
const SIZE: usize;
|
||||||
}
|
}
|
||||||
@ -54,26 +54,26 @@ pub trait ConstSizeAtomic: InlineableAtomic {
|
|||||||
|
|
||||||
impl<A: ConstSizeAtomic> InlineableAtomic for A {}
|
impl<A: ConstSizeAtomic> InlineableAtomic for A {}
|
||||||
|
|
||||||
impl<A: InlineableAtomic> InlineableFactory for AtomicFactory<A> {}
|
impl<'a, Ctx: Context<'a>, A: InlineableAtomic> InlineableFactory<'a, Ctx> for AtomicFactory<A> {}
|
||||||
|
|
||||||
impl<A: ConstSizeAtomic> FixedSizeFactory for AtomicFactory<A> {
|
impl<'a, Ctx: Context<'a>, A: ConstSizeAtomic> FixedSizeFactory<'a, Ctx> for AtomicFactory<A> {
|
||||||
fn size(&self) -> usize {
|
fn size(&self) -> usize {
|
||||||
A::SIZE
|
A::SIZE
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<A: ConstSizeAtomic> ConstSizeFactory for AtomicFactory<A> {
|
impl<'a, Ctx: Context<'a>, A: ConstSizeAtomic> ConstSizeFactory<'a, Ctx> for AtomicFactory<A> {
|
||||||
const SIZE: usize = A::SIZE;
|
const SIZE: usize = A::SIZE;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> InlineableObject<'a, Ctx> for A where
|
impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> InlineableObject<'a, Ctx> for A where
|
||||||
A::Fctr: InlineableFactory
|
A::Fctr: InlineableFactory<'a, Ctx>
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> FixedSizeObject<'a, Ctx> for A
|
impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> FixedSizeObject<'a, Ctx> for A
|
||||||
where
|
where
|
||||||
A::Fctr: FixedSizeFactory,
|
A::Fctr: FixedSizeFactory<'a, Ctx>,
|
||||||
{
|
{
|
||||||
fn size(&self) -> usize {
|
fn size(&self) -> usize {
|
||||||
self.factory().size()
|
self.factory().size()
|
||||||
@ -82,7 +82,7 @@ where
|
|||||||
|
|
||||||
impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> ConstSizeObject<'a, Ctx> for A
|
impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> ConstSizeObject<'a, Ctx> for A
|
||||||
where
|
where
|
||||||
A::Fctr: ConstSizeFactory,
|
A::Fctr: ConstSizeFactory<'a, Ctx>,
|
||||||
{
|
{
|
||||||
const SIZE: usize = A::Fctr::SIZE;
|
const SIZE: usize = A::Fctr::SIZE;
|
||||||
}
|
}
|
||||||
@ -134,7 +134,7 @@ pub type CheckedParseResult<'a, Ctx, F> =
|
|||||||
Result<Mtbl<'a, Ctx, F>, CheckedParseError<ParseError<'a, Ctx, F>>>;
|
Result<Mtbl<'a, Ctx, F>, CheckedParseError<ParseError<'a, Ctx, F>>>;
|
||||||
|
|
||||||
/// Extension trait for factories that ensures fixed size read.
|
/// Extension trait for factories that ensures fixed size read.
|
||||||
pub trait CheckedParse<'a, Ctx: Context<'a>>: FixedSizeFactory + Factory<'a, Ctx> {
|
pub trait CheckedParse<'a, Ctx: Context<'a>>: FixedSizeFactory<'a, Ctx> {
|
||||||
/// Verify proper read length using [`Deserializer::tell`].
|
/// Verify proper read length using [`Deserializer::tell`].
|
||||||
fn deserialize_checked(
|
fn deserialize_checked(
|
||||||
&self,
|
&self,
|
||||||
@ -150,7 +150,7 @@ pub trait CheckedSerialize<'a, Ctx: Context<'a>>: Serializable + FixedSizeObject
|
|||||||
fn serialize_checked(&self, serializer: &mut dyn Serializer) -> Result<(), SizeError>;
|
fn serialize_checked(&self, serializer: &mut dyn Serializer) -> Result<(), SizeError>;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, Ctx: Context<'a>, F: FixedSizeFactory + Factory<'a, Ctx>> CheckedParse<'a, Ctx> for F {
|
impl<'a, Ctx: Context<'a>, F: FixedSizeFactory<'a, Ctx>> CheckedParse<'a, Ctx> for F {
|
||||||
fn deserialize_checked(
|
fn deserialize_checked(
|
||||||
&self,
|
&self,
|
||||||
deserializer: &mut dyn Deserializer,
|
deserializer: &mut dyn Deserializer,
|
||||||
@ -200,9 +200,9 @@ pub trait AlwaysFixedSize {
|
|||||||
fn _size(&self) -> usize;
|
fn _size(&self) -> usize;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<F: AlwaysFixedSize> InlineableFactory for F {}
|
impl<'a, Ctx: Context<'a>, F: AlwaysFixedSize + Factory<'a, Ctx>> InlineableFactory<'a, Ctx> for F {}
|
||||||
|
|
||||||
impl<F: AlwaysFixedSize> FixedSizeFactory 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()
|
||||||
}
|
}
|
||||||
@ -219,7 +219,7 @@ impl<F: AlwaysConstSize> AlwaysFixedSize for F {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<F: AlwaysConstSize> ConstSizeFactory for F {
|
impl<'a, Ctx: Context<'a>, F: AlwaysConstSize + Factory<'a, Ctx>> ConstSizeFactory<'a, Ctx> for F {
|
||||||
const SIZE: usize = Self::_SIZE;
|
const SIZE: usize = Self::_SIZE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,7 +37,7 @@ pub trait StaticPair<'a, Ctx: Context<'a>>:
|
|||||||
/// Second element's type. Must equal [`StaticPairSerializable::SB`].
|
/// Second element's type. Must equal [`StaticPairSerializable::SB`].
|
||||||
type B: Mentionable<'a, Ctx, Fctr = Self::FB>;
|
type B: Mentionable<'a, Ctx, Fctr = Self::FB>;
|
||||||
/// First element's factory.
|
/// First element's factory.
|
||||||
type FA: Factory<'a, Ctx, Mtbl = Self::A> + InlineableFactory;
|
type FA: Factory<'a, Ctx, Mtbl = Self::A> + InlineableFactory<'a, Ctx>;
|
||||||
/// Second element's factory.
|
/// Second element's factory.
|
||||||
type FB: Factory<'a, Ctx, Mtbl = Self::B>;
|
type FB: Factory<'a, Ctx, Mtbl = Self::B>;
|
||||||
/// See [Factory::ParseError].
|
/// See [Factory::ParseError].
|
||||||
@ -156,18 +156,18 @@ impl<'a, Ctx: Context<'a>, SP: StaticPair<'a, Ctx>> Factory<'a, Ctx>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, Ctx: Context<'a>, SP: StaticPair<'a, Ctx>> InlineableFactory
|
impl<'a, Ctx: Context<'a>, SP: StaticPair<'a, Ctx>> InlineableFactory<'a, Ctx>
|
||||||
for StaticPairFactory<'a, Ctx, SP>
|
for StaticPairFactory<'a, Ctx, SP>
|
||||||
where
|
where
|
||||||
SP::FB: InlineableFactory,
|
SP::FB: InlineableFactory<'a, Ctx>,
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, Ctx: Context<'a>, SP: StaticPair<'a, Ctx>> FixedSizeFactory
|
impl<'a, Ctx: Context<'a>, SP: StaticPair<'a, Ctx>> FixedSizeFactory<'a, Ctx>
|
||||||
for StaticPairFactory<'a, Ctx, SP>
|
for StaticPairFactory<'a, Ctx, SP>
|
||||||
where
|
where
|
||||||
SP::FA: FixedSizeFactory,
|
SP::FA: FixedSizeFactory<'a, Ctx>,
|
||||||
SP::FB: FixedSizeFactory,
|
SP::FB: FixedSizeFactory<'a, Ctx>,
|
||||||
{
|
{
|
||||||
fn size(&self) -> usize {
|
fn size(&self) -> usize {
|
||||||
let (fa, fb) = SP::factories(&self.factory_data);
|
let (fa, fb) = SP::factories(&self.factory_data);
|
||||||
@ -175,11 +175,11 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, Ctx: Context<'a>, SP: StaticPair<'a, Ctx>> ConstSizeFactory
|
impl<'a, Ctx: Context<'a>, SP: StaticPair<'a, Ctx>> ConstSizeFactory<'a, Ctx>
|
||||||
for StaticPairFactory<'a, Ctx, SP>
|
for StaticPairFactory<'a, Ctx, SP>
|
||||||
where
|
where
|
||||||
SP::FA: ConstSizeFactory,
|
SP::FA: ConstSizeFactory<'a, Ctx>,
|
||||||
SP::FB: ConstSizeFactory,
|
SP::FB: ConstSizeFactory<'a, Ctx>,
|
||||||
{
|
{
|
||||||
const SIZE: usize = SP::FA::SIZE + SP::FB::SIZE;
|
const SIZE: usize = SP::FA::SIZE + SP::FB::SIZE;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user