From 86b87306ef488eb165b44964bcad643f7c41163d Mon Sep 17 00:00:00 2001 From: timofey Date: Sun, 7 May 2023 16:37:43 +0000 Subject: [PATCH] Point::points_typed --- src/core.rs | 5 ++++- src/core/points.rs | 2 +- src/core/typeless.rs | 6 ++++++ src/std/atomic/atomic_object.rs | 2 ++ src/std/collections/rbtree.rs | 19 +++++++++++++++++++ src/std/collections/stack.rs | 5 +++++ src/std/inlining/static_pair.rs | 6 ++++++ src/std/nullable.rs | 7 +++++++ src/std/point.rs | 4 ++++ 9 files changed, 54 insertions(+), 2 deletions(-) diff --git a/src/core.rs b/src/core.rs index 6cfd8f5..e72d986 100644 --- a/src/core.rs +++ b/src/core.rs @@ -17,6 +17,7 @@ use crate::func::*; pub use self::addresses::*; pub use self::hashing::*; +pub use self::points::TakesPoints; pub use self::resolution::*; pub use self::serialization::*; pub use self::slice_deserializer::*; @@ -71,7 +72,9 @@ pub trait Mentionable<'a, Ctx: 'a + Context>: 'a + Serializable { } Ctx::hash(&vec) } - /// References ([Point]s) to other objects. + /// References ([Point]s) to other objects. Typed. + fn points_typed(&self, points: &mut impl TakesPoints<'a, Ctx>); + /// References ([Point]s) to other objects. Typeless. fn points(&self, points: &mut Vec>>); /// [Vec] of [Point]s as used by [`Mentionable::topology`]. fn points_vec(&self) -> Vec>> { diff --git a/src/core/points.rs b/src/core/points.rs index 39cc068..b7316f3 100644 --- a/src/core/points.rs +++ b/src/core/points.rs @@ -1,5 +1,5 @@ use super::*; pub trait TakesPoints<'a, Ctx: 'a + Context> { - fn take>(&mut self, point: Point<'a, Ctx, A>); + fn take>(&mut self, point: &Point<'a, Ctx, A>); } diff --git a/src/core/typeless.rs b/src/core/typeless.rs index 6253303..f80534e 100644 --- a/src/core/typeless.rs +++ b/src/core/typeless.rs @@ -56,6 +56,12 @@ impl<'a, Ctx: 'a + Context> Mentionable<'a, Ctx> for TypelessMentionable<'a, Ctx self.t_topology } + fn points_typed(&self, points: &mut impl TakesPoints<'a, Ctx>) { + for point in self.t_points.iter() { + points.take(point) + } + } + fn points(&self, points: &mut Vec>>) { points.extend(self.t_points.iter().map(Clone::clone)); } diff --git a/src/std/atomic/atomic_object.rs b/src/std/atomic/atomic_object.rs index 0e45b73..fcd3052 100644 --- a/src/std/atomic/atomic_object.rs +++ b/src/std/atomic/atomic_object.rs @@ -46,6 +46,8 @@ impl<'a, Ctx: 'a + Context, A: Atomic> Mentionable<'a, Ctx> for AtomicObject Ctx::hash(b"") } + fn points_typed(&self, _points: &mut impl TakesPoints<'a, Ctx>) {} + fn points(&self, _points: &mut Vec>>) {} } diff --git a/src/std/collections/rbtree.rs b/src/std/collections/rbtree.rs index 9783af7..6f727b1 100644 --- a/src/std/collections/rbtree.rs +++ b/src/std/collections/rbtree.rs @@ -132,6 +132,13 @@ impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> Mentionable<'a, Ctx> for RB } } + fn points_typed(&self, points: &mut impl TakesPoints<'a, Ctx>) { + match self { + RBNode::R(r) => r.points_typed(points), + RBNode::B(b) => b.points_typed(points), + } + } + fn points(&self, points: &mut Vec>>) { match self { RBNode::R(r) => r.points(points), @@ -149,6 +156,12 @@ impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> Mentionable<'a, Ctx> for BN } } + fn points_typed(&self, points: &mut impl TakesPoints<'a, Ctx>) { + self.cl.points_typed(points); + self.cr.points_typed(points); + self.key.points_typed(points); + } + fn points(&self, points: &mut Vec>>) { self.cl.points(points); self.cr.points(points); @@ -165,6 +178,12 @@ impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> Mentionable<'a, Ctx> for RN } } + fn points_typed(&self, points: &mut impl TakesPoints<'a, Ctx>) { + self.cl.points_typed(points); + self.cr.points_typed(points); + self.key.points_typed(points); + } + fn points(&self, points: &mut Vec>>) { self.cl.points(points); self.cr.points(points); diff --git a/src/std/collections/stack.rs b/src/std/collections/stack.rs index 72c673e..919ea08 100644 --- a/src/std/collections/stack.rs +++ b/src/std/collections/stack.rs @@ -42,6 +42,11 @@ impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> Mentionable<'a, Ctx> StackNodeFactory::new(self.element.factory()) } + fn points_typed(&self, points: &mut impl TakesPoints<'a, Ctx>) { + self.rest.points_typed(points); + self.element.points_typed(points); + } + fn points(&self, points: &mut Vec>>) { self.rest.points(points); self.element.points(points); diff --git a/src/std/inlining/static_pair.rs b/src/std/inlining/static_pair.rs index a7c1255..9592185 100644 --- a/src/std/inlining/static_pair.rs +++ b/src/std/inlining/static_pair.rs @@ -108,6 +108,12 @@ impl<'a, Ctx: 'a + Context, SP: StaticPair<'a, Ctx>> Mentionable<'a, Ctx> for St } } + fn points_typed(&self, points: &mut impl TakesPoints<'a, Ctx>) { + let (a, b) = self.pair.elements(); + a.points_typed(points); + b.points_typed(points); + } + fn points(&self, points: &mut Vec>>) { let (a, b) = self.pair.elements(); a.points(points); diff --git a/src/std/nullable.rs b/src/std/nullable.rs index f560ec4..7ca52d0 100644 --- a/src/std/nullable.rs +++ b/src/std/nullable.rs @@ -41,6 +41,13 @@ impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> Mentionable<'a, Ctx> for Nu } } + fn points_typed(&self, points: &mut impl TakesPoints<'a, Ctx>) { + match self { + Nullable::Null(_) => {} + Nullable::NotNull(point) => points.take(point), + } + } + fn points(&self, points: &mut Vec>>) { match self { Nullable::Null(_) => {} diff --git a/src/std/point.rs b/src/std/point.rs index e0b0d6f..0911079 100644 --- a/src/std/point.rs +++ b/src/std/point.rs @@ -23,6 +23,10 @@ impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> Mentionable<'a, Ctx> for Po Ctx::hash(&self.point) } + fn points_typed(&self, points: &mut impl TakesPoints<'a, Ctx>) { + points.take(self) + } + fn points(&self, points: &mut Vec>>) { points.push(self.typeless()); }