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