blanket SingularCtx
This commit is contained in:
parent
160aa3910a
commit
0fe1405898
@ -45,7 +45,7 @@ pub struct SingularRobust<'a, Ctx: Context<'a>> {
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum SingularityError {
|
||||
pub enum SingularError {
|
||||
OutOfBounds {
|
||||
index: usize,
|
||||
len: usize,
|
||||
@ -57,7 +57,7 @@ pub enum SingularityError {
|
||||
},
|
||||
}
|
||||
|
||||
impl Display for SingularityError {
|
||||
impl Display for SingularError {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
Self::OutOfBounds { index, len } => {
|
||||
@ -87,16 +87,16 @@ impl<'a, Ctx: Context<'a>> SingularResolver<'a, Ctx> {
|
||||
fn resolve_robust(
|
||||
self: Arc<Self>,
|
||||
address: Address,
|
||||
) -> Result<HashResolution<'a, Ctx>, SingularityError> {
|
||||
) -> Result<HashResolution<'a, Ctx>, SingularError> {
|
||||
let point = self
|
||||
.points
|
||||
.get(address.index)
|
||||
.ok_or(SingularityError::OutOfBounds {
|
||||
.ok_or(SingularError::OutOfBounds {
|
||||
index: address.index,
|
||||
len: self.points.len(),
|
||||
})?;
|
||||
if point.s_hash() != address.point {
|
||||
Err(SingularityError::Mismatch {
|
||||
Err(SingularError::Mismatch {
|
||||
index: address.index,
|
||||
expected: address.point,
|
||||
point: point.s_hash(),
|
||||
@ -114,7 +114,16 @@ impl<'a, Ctx: Context<'a>> Resolver<'a, Ctx> for SingularResolver<'a, Ctx> {
|
||||
}
|
||||
|
||||
trait SingularCtx<'a>: Context<'a> {
|
||||
fn from_singular(error: SingularityError) -> Self::LookupError;
|
||||
fn from_singular(error: SingularError) -> Self::LookupError;
|
||||
}
|
||||
|
||||
impl<'a, Ctx: Context<'a>> SingularCtx<'a> for Ctx
|
||||
where
|
||||
Ctx::LookupError: From<SingularError>,
|
||||
{
|
||||
fn from_singular(error: SingularError) -> Self::LookupError {
|
||||
error.into()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, Ctx: SingularCtx<'a>> Resolver<'a, Ctx> for SingularRobust<'a, Ctx> {
|
||||
|
Loading…
Reference in New Issue
Block a user