use crate::rcore::*; use super::*; trait SingularResolution<'a, Ctx: Context<'a>>: 'a + Send + Sync { fn singular(self: Arc) -> HashResolution<'a, Ctx>; fn s_hash(&self) -> Hash; } impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> SingularResolution<'a, Ctx> for Point<'a, Ctx, A> { fn singular(self: Arc) -> HashResolution<'a, Ctx> { self.origin.clone().resolve_bytes() } fn s_hash(&self) -> Hash { self.point } } pub struct SingularResolver<'a, Ctx: Context<'a>> { points: Vec>>, } 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 } } } impl<'a, Ctx: Context<'a>> Resolver<'a, Ctx> for SingularResolver<'a, Ctx> { fn resolve(self: Arc, address: Address) -> HashResolution<'a, Ctx> { let point = self.points.get(address.index).unwrap_or_else(|| { panic!( "singularity out-of-bounds: {}/{}", address.index, self.points.len() ) }); if point.s_hash() != address.point { panic!( "address mismatch at index {}: {}!={}", address.index, hex::encode(address.point), hex::encode(point.s_hash()), ) } point.clone().singular() } } impl<'a, Ctx: Context<'a>> PointsVisitor<'a, Ctx> for Vec>> { fn visit>(&mut self, point: &Point<'a, Ctx, A>) { self.push(Arc::new(point.clone()) as _); } }