rcore::topology
All checks were successful
buildbot/cargo fmt (1.72) Build done.
buildbot/cargo doc (1.72) Build done.
buildbot/cargo clippy (1.72) Build done.
buildbot/cargo test (1.65) Build done.
buildbot/cargo clippy (1.65) Build done.

This commit is contained in:
AF 2023-09-03 20:08:42 +00:00
parent 01c9fd26ba
commit 116507fad8
2 changed files with 23 additions and 19 deletions

View File

@ -17,6 +17,7 @@ mod points;
mod regular; mod regular;
mod resolution; mod resolution;
mod resolver_origin; mod resolver_origin;
mod topology;
use std::{error::Error, sync::Arc}; use std::{error::Error, sync::Arc};
@ -40,6 +41,7 @@ pub use self::resolution::{
Address, HashResolution, HashResolutionResult, LookupError, Resolution, ResolutionError, Address, HashResolution, HashResolutionResult, LookupError, Resolution, ResolutionError,
ResolutionFailure, ResolutionResult, Resolver, ResolverMap, ResolutionFailure, ResolutionResult, Resolver, ResolverMap,
}; };
pub use self::topology::MentionableTop;
/// Helper alias for [`WeakFunctor::F`] of [`FunctorContext::T`]. /// 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; 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. /// Fundamental trait for ADN objects.
pub trait Mentionable<'a, Ctx: Context<'a>>: pub trait Mentionable<'a, Ctx: Context<'a>>:
MentionableBase<'a, Fctr = Self::_Fctr> + MentionableTop<'a, Ctx> MentionableBase<'a, Fctr = Self::_Fctr> + MentionableTop<'a, Ctx>

21
src/rcore/topology.rs Normal file
View File

@ -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>;
}