From a28bfa461e2ebc34312053617e12f2383416aa33 Mon Sep 17 00:00:00 2001 From: timofey Date: Sun, 3 Sep 2023 21:37:28 +0000 Subject: [PATCH] `SingularResolver` via `Topology` --- src/rcore/topology.rs | 2 +- src/rstd/singular.rs | 18 +++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/rcore/topology.rs b/src/rcore/topology.rs index 5af0db8..5e5df95 100644 --- a/src/rcore/topology.rs +++ b/src/rcore/topology.rs @@ -37,7 +37,7 @@ impl<'a, Ctx: Context<'a>> PointsVisitor<'a, Ctx> for TopoVec<'a, Ctx> { } } -pub trait Topology<'a, Ctx: Context<'a>>: 'a { +pub trait Topology<'a, Ctx: Context<'a>>: 'a + Send + Sync { fn points_count(&self) -> usize; fn point_at(&self, index: usize) -> Option>>; diff --git a/src/rstd/singular.rs b/src/rstd/singular.rs index 8985360..8ce4ac2 100644 --- a/src/rstd/singular.rs +++ b/src/rstd/singular.rs @@ -18,26 +18,26 @@ use super::*; /// # } /// ``` pub struct SingularResolver<'a, Ctx: Context<'a>> { - points: TopoVec<'a, Ctx>, + topology: Arc>, } impl<'a, Ctx: Context<'a>> SingularResolver<'a, Ctx> { pub fn from_mentionable>(a: &A) -> Self { - let mut points = Vec::new(); - a.points_typed(&mut points); - Self { points } + Self { + topology: a.topology(), + } } - fn resolve_robust( + fn try_resolve( self: Arc, address: Address, ) -> Result, SingularError> { let point = self - .points - .get(address.index) + .topology + .point_at(address.index) .ok_or(SingularError::OutOfBounds { index: address.index, - len: self.points.len(), + len: self.topology.points_count(), })?; if point.s_hash() != address.point { Err(SingularError::Mismatch { @@ -53,7 +53,7 @@ impl<'a, Ctx: Context<'a>> SingularResolver<'a, Ctx> { impl<'a, Ctx: Context<'a>> Resolver<'a, Ctx> for SingularResolver<'a, Ctx> { fn resolve(self: Arc, address: Address) -> HashResolution<'a, Ctx> { - self.resolve_robust(address) + self.try_resolve(address) .map_err(SingularError::into) .map_err(Err) .unwrap_or_else(Ctx::pure)