From 116507fad899fbfb7abb36b48e22a3128ad75d8e Mon Sep 17 00:00:00 2001 From: timofey Date: Sun, 3 Sep 2023 20:08:42 +0000 Subject: [PATCH] `rcore::topology` --- src/rcore.rs | 21 ++------------------- src/rcore/topology.rs | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 19 deletions(-) create mode 100644 src/rcore/topology.rs diff --git a/src/rcore.rs b/src/rcore.rs index 5367243..d669484 100644 --- a/src/rcore.rs +++ b/src/rcore.rs @@ -17,6 +17,7 @@ mod points; mod regular; mod resolution; mod resolver_origin; +mod topology; use std::{error::Error, sync::Arc}; @@ -40,6 +41,7 @@ pub use self::resolution::{ Address, HashResolution, HashResolutionResult, LookupError, Resolution, ResolutionError, ResolutionFailure, ResolutionResult, Resolver, ResolverMap, }; +pub use self::topology::MentionableTop; /// Helper alias for [`WeakFunctor::F`] of [`FunctorContext::T`]. /// @@ -55,25 +57,6 @@ pub trait MentionableBase<'a>: 'a + Send + Sync + Serializable + Sized { fn factory(&self) -> Self::Fctr; } -/// Topological [Mentionable]. Allows iterating over [Point]s it references, if any; -pub trait MentionableTop<'a, Ctx: Context<'a>>: 'a { - /// See implementation for the definition. - /// Hash of all the references' points concatenated, ordered, non-unique. - /// Used for walking over object trees to ensure two objects with different references don't collide. - fn topology(&self) -> Hash - where - Self: Mentionable<'a, Ctx>, - { - let mut vec = Vec::new(); - self.points_typed(&mut vec); - Ctx::hash(&vec) - } - /// References ([Point]s) to other objects. Typed. - fn points_typed(&self, points: &mut impl PointsVisitor<'a, Ctx>) - where - Self: Mentionable<'a, Ctx>; -} - /// Fundamental trait for ADN objects. pub trait Mentionable<'a, Ctx: Context<'a>>: MentionableBase<'a, Fctr = Self::_Fctr> + MentionableTop<'a, Ctx> diff --git a/src/rcore/topology.rs b/src/rcore/topology.rs new file mode 100644 index 0000000..a126a51 --- /dev/null +++ b/src/rcore/topology.rs @@ -0,0 +1,21 @@ +use super::*; + +/// Topological [Mentionable]. Allows iterating over [Point]s it references, if any; +pub trait MentionableTop<'a, Ctx: Context<'a>>: 'a { + /// See implementation for the definition. + /// Hash of all the references' points concatenated, ordered, non-unique. + /// Used for walking over object trees to ensure two objects with different references don't collide. + fn topology(&self) -> Hash + where + Self: Mentionable<'a, Ctx>, + { + let mut vec = Vec::new(); + self.points_typed(&mut vec); + Ctx::hash(&vec) + } + + /// References ([Point]s) to other objects. Typed. + fn points_typed(&self, points: &mut impl PointsVisitor<'a, Ctx>) + where + Self: Mentionable<'a, Ctx>; +}