From 9d3da4f97c1a2a450b749adaaf0f2a4058eb8345 Mon Sep 17 00:00:00 2001 From: timofey Date: Fri, 16 Jun 2023 05:22:41 +0000 Subject: [PATCH] simplify `StackNodeFactory` --- src/rstd/collections/stack.rs | 47 +++++++++++++---------------------- 1 file changed, 17 insertions(+), 30 deletions(-) diff --git a/src/rstd/collections/stack.rs b/src/rstd/collections/stack.rs index 8377756..e775606 100644 --- a/src/rstd/collections/stack.rs +++ b/src/rstd/collections/stack.rs @@ -15,12 +15,13 @@ pub struct StackNode<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> { /// Type representing a stack, an alias to a [Nullable] of a [StackNode]. pub type Stack<'a, Ctx, A> = Nullable<'a, Ctx, StackNode<'a, Ctx, A>>; -pub struct StackNodeFactory<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> { - element_factory: A::Fctr, +#[derive(Clone)] +pub struct StackNodeFactory { + element_factory: F, } -impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> StackNodeFactory<'a, Ctx, A> { - fn new(factory: A::Fctr) -> Self { +impl StackNodeFactory { + fn new(factory: F) -> Self { StackNodeFactory { element_factory: factory, } @@ -35,7 +36,7 @@ impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> Serializable for StackNode<' } impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> Mentionable<'a, Ctx> for StackNode<'a, Ctx, A> { - type Fctr = StackNodeFactory<'a, Ctx, A>; + type Fctr = StackNodeFactory; fn factory(&self) -> Self::Fctr { StackNodeFactory::new(self.element.factory()) @@ -47,12 +48,6 @@ impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> Mentionable<'a, Ctx> for Sta } } -impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> Clone for StackNodeFactory<'a, Ctx, A> { - fn clone(&self) -> Self { - StackNodeFactory::new(self.element_factory.clone()) - } -} - #[derive(Debug)] pub enum StackParseError { Point(PointParseError), @@ -74,12 +69,10 @@ impl Display for StackParseError { impl Error for StackParseError {} -impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> Factory<'a, Ctx> - for StackNodeFactory<'a, Ctx, A> -{ - type Mtbl = StackNode<'a, Ctx, A>; +impl<'a, Ctx: Context<'a>, F: Factory<'a, Ctx>> Factory<'a, Ctx> for StackNodeFactory { + type Mtbl = StackNode<'a, Ctx, F::Mtbl>; - type ParseError = StackParseError>; + type ParseError = StackParseError>; fn deserialize( &self, @@ -172,29 +165,23 @@ 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<'a, Ctx> - for StackNodeFactory<'a, Ctx, A> -where - A::Fctr: InlineableFactory<'a, Ctx>, +impl<'a, Ctx: Context<'a>, F: InlineableFactory<'a, Ctx>> InlineableFactory<'a, Ctx> + for StackNodeFactory { } -impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> FixedSizeFactory<'a, Ctx> - for StackNodeFactory<'a, Ctx, A> -where - A::Fctr: FixedSizeFactory<'a, Ctx>, +impl<'a, Ctx: Context<'a>, F: FixedSizeFactory<'a, Ctx>> FixedSizeFactory<'a, Ctx> + for StackNodeFactory { fn size(&self) -> usize { - Stack::<'a, Ctx, A>::SIZE + self.element_factory.size() + Stack::<'a, Ctx, F::Mtbl>::SIZE + self.element_factory.size() } } -impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> ConstSizeFactory<'a, Ctx> - for StackNodeFactory<'a, Ctx, A> -where - A::Fctr: ConstSizeFactory<'a, Ctx>, +impl<'a, Ctx: Context<'a>, F: ConstSizeFactory<'a, Ctx>> ConstSizeFactory<'a, Ctx> + for StackNodeFactory { - const SIZE: usize = Stack::<'a, Ctx, A>::SIZE + A::Fctr::SIZE; + const SIZE: usize = Stack::<'a, Ctx, F::Mtbl>::SIZE + F::SIZE; } #[cfg(test)]