use std::rc::Rc; use crate::core::*; use super::*; impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> Point<'a, Ctx, A> { fn prepare_bytes_for_hashing(mentioned: &A) -> Vec { let mut vec = mentioned.topology().to_vec(); mentioned.serialize(&mut vec); vec } fn from_fields(point: Hash, origin: Rc>) -> Self { Point { point, origin } } fn from_values>(point: Hash, origin: O) -> Self { Self::from_fields(point, Rc::new(origin)) } fn from_mentionable(mentionable: A) -> Self { Self::from_values( Ctx::hash(&Self::prepare_bytes_for_hashing(&mentionable)), LocalOrigin::from(mentionable), ) } } struct LocalOrigin(Rc); impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> Origin<'a, Ctx> for LocalOrigin { type Mtbl = A; fn factory(&self) -> A::Fctr { self.0.factory() } fn resolve(self: Rc) -> Resolution<'a, Ctx, Self::Mtbl> { Ctx::T::pure(Ok(self.0.clone())) } } impl From for LocalOrigin { fn from(value: A) -> Self { LocalOrigin(value.into()) } } impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> From for Point<'a, Ctx, A> { fn from(value: A) -> Self { Self::from_mentionable(value) } }