From 16a54b39125fb17daa38c2d32ef9780d4d5f6f18 Mon Sep 17 00:00:00 2001 From: timofey Date: Sun, 3 Sep 2023 21:30:41 +0000 Subject: [PATCH] `Topology` --- src/rcore/topology.rs | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/src/rcore/topology.rs b/src/rcore/topology.rs index b431f43..5af0db8 100644 --- a/src/rcore/topology.rs +++ b/src/rcore/topology.rs @@ -18,12 +18,37 @@ pub trait MentionableTop<'a, Ctx: Context<'a>>: 'a { fn points_typed(&self, points: &mut impl PointsVisitor<'a, Ctx>) where Self: Mentionable<'a, Ctx>; + + fn topology(&self) -> Arc> + where + Self: Mentionable<'a, Ctx>, + { + let mut vec: TopoVec<'a, Ctx> = Vec::new(); + self.points_typed(&mut vec); + Arc::new(vec) + } } pub type TopoVec<'a, Ctx> = Vec>>; impl<'a, Ctx: Context<'a>> PointsVisitor<'a, Ctx> for TopoVec<'a, Ctx> { fn visit>(&mut self, point: &Point<'a, Ctx, A>) { - self.push(Arc::new(point.clone()) as _); + self.push(Arc::new(point.clone())); + } +} + +pub trait Topology<'a, Ctx: Context<'a>>: 'a { + fn points_count(&self) -> usize; + + fn point_at(&self, index: usize) -> Option>>; +} + +impl<'a, Ctx: Context<'a>> Topology<'a, Ctx> for TopoVec<'a, Ctx> { + fn points_count(&self) -> usize { + self.len() + } + + fn point_at(&self, index: usize) -> Option>> { + self.get(index).cloned() } }