simplify StackNodeFactory
				
					
				
			This commit is contained in:
		
							parent
							
								
									5037ee3c84
								
							
						
					
					
						commit
						9d3da4f97c
					
				| @ -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].
 | /// 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 type Stack<'a, Ctx, A> = Nullable<'a, Ctx, StackNode<'a, Ctx, A>>; | ||||||
| 
 | 
 | ||||||
| pub struct StackNodeFactory<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> { | #[derive(Clone)] | ||||||
|     element_factory: A::Fctr, | pub struct StackNodeFactory<F> { | ||||||
|  |     element_factory: F, | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> StackNodeFactory<'a, Ctx, A> { | impl<F> StackNodeFactory<F> { | ||||||
|     fn new(factory: A::Fctr) -> Self { |     fn new(factory: F) -> Self { | ||||||
|         StackNodeFactory { |         StackNodeFactory { | ||||||
|             element_factory: factory, |             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> { | 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<A::Fctr>; | ||||||
| 
 | 
 | ||||||
|     fn factory(&self) -> Self::Fctr { |     fn factory(&self) -> Self::Fctr { | ||||||
|         StackNodeFactory::new(self.element.factory()) |         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)] | #[derive(Debug)] | ||||||
| pub enum StackParseError<ElementParseError: Error> { | pub enum StackParseError<ElementParseError: Error> { | ||||||
|     Point(PointParseError), |     Point(PointParseError), | ||||||
| @ -74,12 +69,10 @@ impl<ElementParseError: Error> Display for StackParseError<ElementParseError> { | |||||||
| 
 | 
 | ||||||
| impl<ElementParseError: Error> Error for StackParseError<ElementParseError> {} | impl<ElementParseError: Error> Error for StackParseError<ElementParseError> {} | ||||||
| 
 | 
 | ||||||
| impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> Factory<'a, Ctx> | impl<'a, Ctx: Context<'a>, F: Factory<'a, Ctx>> Factory<'a, Ctx> for StackNodeFactory<F> { | ||||||
|     for StackNodeFactory<'a, Ctx, A> |     type Mtbl = StackNode<'a, Ctx, F::Mtbl>; | ||||||
| { |  | ||||||
|     type Mtbl = StackNode<'a, Ctx, A>; |  | ||||||
| 
 | 
 | ||||||
|     type ParseError = StackParseError<ParseError<'a, Ctx, A::Fctr>>; |     type ParseError = StackParseError<ParseError<'a, Ctx, F>>; | ||||||
| 
 | 
 | ||||||
|     fn deserialize( |     fn deserialize( | ||||||
|         &self, |         &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> | impl<'a, Ctx: Context<'a>, F: InlineableFactory<'a, Ctx>> InlineableFactory<'a, Ctx> | ||||||
|     for StackNodeFactory<'a, Ctx, A> |     for StackNodeFactory<F> | ||||||
| where |  | ||||||
|     A::Fctr: InlineableFactory<'a, Ctx>, |  | ||||||
| { | { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> FixedSizeFactory<'a, Ctx> | impl<'a, Ctx: Context<'a>, F: FixedSizeFactory<'a, Ctx>> FixedSizeFactory<'a, Ctx> | ||||||
|     for StackNodeFactory<'a, Ctx, A> |     for StackNodeFactory<F> | ||||||
| where |  | ||||||
|     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, F::Mtbl>::SIZE + self.element_factory.size() | ||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> ConstSizeFactory<'a, Ctx> | impl<'a, Ctx: Context<'a>, F: ConstSizeFactory<'a, Ctx>> ConstSizeFactory<'a, Ctx> | ||||||
|     for StackNodeFactory<'a, Ctx, A> |     for StackNodeFactory<F> | ||||||
| where |  | ||||||
|     A::Fctr: ConstSizeFactory<'a, Ctx>, |  | ||||||
| { | { | ||||||
|     const SIZE: usize = Stack::<'a, Ctx, A>::SIZE + A::Fctr::SIZE; |     const SIZE: usize = Stack::<'a, Ctx, F::Mtbl>::SIZE + F::SIZE; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| #[cfg(test)] | #[cfg(test)] | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user