blanket SingularCtx
All checks were successful
buildbot/cargo fmt (1.72) Build done.
buildbot/cargo doc (1.72) Build done.
buildbot/cargo clippy (1.72) Build done.
buildbot/cargo test (1.65) Build done.
buildbot/cargo clippy (1.65) Build done.

This commit is contained in:
AF 2023-09-03 19:09:29 +00:00
parent 160aa3910a
commit 0fe1405898

View File

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