From b7e3beacb6d3677b549b99eb23190e59521ad880 Mon Sep 17 00:00:00 2001 From: timofey Date: Sat, 29 Jul 2023 15:04:29 +0000 Subject: [PATCH] loosen tree bounds --- src/rstd/collections/tree.rs | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/src/rstd/collections/tree.rs b/src/rstd/collections/tree.rs index f747fea..ba6b0f0 100644 --- a/src/rstd/collections/tree.rs +++ b/src/rstd/collections/tree.rs @@ -55,18 +55,18 @@ impl Display for TreeParseError { impl Error for TreeParseError {} -pub struct Node<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> { +pub struct Node<'a, Ctx: Context<'a>, A: MentionableBase<'a, Ctx>> { l: Tree<'a, Ctx, A>, r: Tree<'a, Ctx, A>, key: A, } -pub struct Tree<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> { +pub struct Tree<'a, Ctx: Context<'a>, A: MentionableBase<'a, Ctx>> { node: Nullable<'a, Ctx, Node<'a, Ctx, A>>, height: u64, } -impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> Tree<'a, Ctx, A> { +impl<'a, Ctx: Context<'a>, A: MentionableBase<'a, Ctx>> Tree<'a, Ctx, A> { fn validate_height(&self) -> Result<(), HeightError> { if let Nullable::Null(_) = self.node { if self.height != 0 { @@ -85,7 +85,7 @@ pub struct NodeFactory(F); #[derive(Clone)] pub struct TreeFactory(NullableFactory>); -impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> Serializable for Node<'a, Ctx, A> { +impl<'a, Ctx: Context<'a>, A: MentionableBase<'a, Ctx>> Serializable for Node<'a, Ctx, A> { fn serialize(&self, serializer: &mut dyn Serializer) { self.l.serialize(serializer); self.r.serialize(serializer); @@ -93,14 +93,16 @@ impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> Serializable for Node<'a, Ct } } -impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> Serializable for Tree<'a, Ctx, A> { +impl<'a, Ctx: Context<'a>, A: MentionableBase<'a, Ctx>> Serializable for Tree<'a, Ctx, A> { fn serialize(&self, serializer: &mut dyn Serializer) { self.height.serialize(serializer); self.node.serialize(serializer); } } -impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> MentionableBase<'a, Ctx> for Node<'a, Ctx, A> { +impl<'a, Ctx: Context<'a>, A: MentionableBase<'a, Ctx>> MentionableBase<'a, Ctx> + for Node<'a, Ctx, A> +{ type Fctr = NodeFactory; fn factory(&self) -> Self::Fctr { @@ -116,7 +118,9 @@ impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> MentionableTop<'a, Ctx> for } } -impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> MentionableBase<'a, Ctx> for Tree<'a, Ctx, A> { +impl<'a, Ctx: Context<'a>, A: MentionableBase<'a, Ctx>> MentionableBase<'a, Ctx> + for Tree<'a, Ctx, A> +{ type Fctr = TreeFactory; fn factory(&self) -> Self::Fctr { @@ -130,7 +134,7 @@ impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> MentionableTop<'a, Ctx> for } } -impl<'a, Ctx: Context<'a>, F: Factory<'a, Ctx>> FactoryBase<'a, Ctx> for NodeFactory { +impl<'a, Ctx: Context<'a>, F: FactoryBase<'a, Ctx>> FactoryBase<'a, Ctx> for NodeFactory { type Mtbl = Node<'a, Ctx, F::Mtbl>; type ParseError = TreeParseError; @@ -140,7 +144,7 @@ impl ParseMode for NodeFactory { type Mode = RegularMode; } -impl<'a, Ctx: Context<'a>, F: Factory<'a, Ctx>> RegularFactory<'a, Ctx> for NodeFactory { +impl<'a, Ctx: Context<'a>, F: FactoryParse<'a, Ctx>> RegularFactory<'a, Ctx> for NodeFactory { fn rdeserialize(&self, inctx: impl InCtx<'a, Ctx>) -> ParseResult<'a, Ctx, Self> { let tree_factory = TreeFactory(NullableFactory::new(self.clone())); let (l, inctx) = tree_factory.ideserialize(inctx)?; @@ -158,7 +162,7 @@ impl<'a, Ctx: Context<'a>, F: Factory<'a, Ctx>> RegularFactory<'a, Ctx> for Node } } -impl<'a, Ctx: Context<'a>, F: Factory<'a, Ctx>> FactoryBase<'a, Ctx> for TreeFactory { +impl<'a, Ctx: Context<'a>, F: FactoryBase<'a, Ctx>> FactoryBase<'a, Ctx> for TreeFactory { type Mtbl = Tree<'a, Ctx, F::Mtbl>; type ParseError = TreeParseError; @@ -168,7 +172,7 @@ impl ParseMode for TreeFactory { type Mode = InliningMode; } -impl<'a, Ctx: Context<'a>, F: Factory<'a, Ctx>> InlineableFactory<'a, Ctx> for TreeFactory { +impl<'a, Ctx: Context<'a>, F: FactoryParse<'a, Ctx>> InlineableFactory<'a, Ctx> for TreeFactory { fn extension_error(&self, tail: &[u8]) -> Self::ParseError { u64::a_extension_error(tail).into() } @@ -182,7 +186,7 @@ impl<'a, Ctx: Context<'a>, F: Factory<'a, Ctx>> InlineableFactory<'a, Ctx> for T } } -impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx> + Clone> Clone for Node<'a, Ctx, A> { +impl<'a, Ctx: Context<'a>, A: MentionableBase<'a, Ctx> + Clone> Clone for Node<'a, Ctx, A> { fn clone(&self) -> Self { Self { l: self.l.clone(), @@ -192,7 +196,7 @@ impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx> + Clone> Clone for Node<'a, C } } -impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx> + Clone> Clone for Tree<'a, Ctx, A> { +impl<'a, Ctx: Context<'a>, A: MentionableBase<'a, Ctx> + Clone> Clone for Tree<'a, Ctx, A> { fn clone(&self) -> Self { Self { node: self.node.clone(),