1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
use super::*;

/// The main way to represent a reference in ADN.
pub struct Point<'a, Ctx: Context<'a>, A: MentionableBase<'a>> {
    /// Hash of the referred content.
    /// Derived both from the serialised value ([`Serializable::serialize`])
    /// and its topology ([`MentionableTop::topology_hash`]).
    pub point: Hash,
    /// [Origin] used in [`Point::resolve`].
    pub origin: Arc<dyn Origin<'a, Ctx, Mtbl = A>>,
}

impl<'a, Ctx: Context<'a>, A: MentionableBase<'a>> PartialEq for Point<'a, Ctx, A> {
    /// Note: this doesn't check for [Factory] equality.
    fn eq(&self, other: &Self) -> bool {
        self.point == other.point
    }
}

impl<'a, Ctx: Context<'a>, A: MentionableBase<'a>> Clone for Point<'a, Ctx, A> {
    fn clone(&self) -> Self {
        Self {
            point: self.point,
            origin: self.origin.clone(),
        }
    }
}

impl<'a, Ctx: Context<'a>, A: MentionableBase<'a>> Point<'a, Ctx, A>
where
    A::Fctr: FactoryParse<'a, Ctx>,
{
    /// See [`Origin::resolve`].
    pub fn resolve(&self) -> Resolution<'a, Ctx, A> {
        self.origin.ref_resolve()
    }

    /// Resolve the object, then map the [ResolutionResult].
    pub fn resolve_map<B: 'a + Send>(
        &self,
        f: impl 'a + Send + FnOnce(ResolutionResult<'a, Ctx, A>) -> B,
    ) -> Wrapped<'a, Ctx, B> {
        self.origin.resolve_map(f)
    }
}