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 {}