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
46
47
48
49
50
51
52
53
54
55
56
use std::fmt::Display;

use super::*;

pub trait SingularResolution<'a, Ctx: Context<'a>>: 'a + Send + Sync {
    fn singular(self: Arc<Self>) -> 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<Self>) -> HashResolution<'a, Ctx> {
        self.origin.ref_resolve_bytes()
    }

    fn s_hash(&self) -> Hash {
        self.point
    }
}

#[derive(Debug)]
pub enum SingularError {
    OutOfBounds {
        index: usize,
        len: usize,
    },
    Mismatch {
        index: usize,
        expected: Hash,
        point: Hash,
    },
}

impl Display for SingularError {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            Self::OutOfBounds { index, len } => {
                write!(f, "singularity out-of-bounds: {index}/{len}")
            }
            Self::Mismatch {
                index,
                expected,
                point,
            } => write!(
                f,
                "address mismatch at index {index}: {}!={}",
                hex(expected),
                hex(point),
            ),
        }
    }
}

impl Error for SingularError {}