SingularError to rcore
All checks were successful
buildbot/cargo fmt (1.72) Build done.
buildbot/cargo clippy (1.65) Build done.
buildbot/cargo doc (1.72) Build done.
buildbot/cargo clippy (1.72) Build done.
buildbot/cargo test (1.65) Build done.

This commit is contained in:
AF 2023-09-03 20:35:19 +00:00
parent e317ce37c1
commit ae95e99767
4 changed files with 38 additions and 37 deletions

View File

@ -43,7 +43,7 @@ pub use self::resolution::{
Address, HashResolution, HashResolutionResult, LookupError, Resolution, ResolutionError, Address, HashResolution, HashResolutionResult, LookupError, Resolution, ResolutionError,
ResolutionFailure, ResolutionResult, Resolver, ResolverMap, ResolutionFailure, ResolutionResult, Resolver, ResolverMap,
}; };
pub use self::singular::SingularResolution; pub use self::singular::{SingularError, SingularResolution};
pub use self::to_hex::hex; pub use self::to_hex::hex;
pub use self::topology::MentionableTop; pub use self::topology::MentionableTop;

View File

@ -1,3 +1,5 @@
use std::fmt::Display;
use super::*; use super::*;
pub trait SingularResolution<'a, Ctx: Context<'a>>: 'a + Send + Sync { pub trait SingularResolution<'a, Ctx: Context<'a>>: 'a + Send + Sync {
@ -17,3 +19,38 @@ impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> SingularResolution<'a, Ctx>
self.point 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 {}

View File

@ -25,41 +25,6 @@ struct SingularRobust<'a, Ctx: Context<'a>> {
resolver: Arc<SingularResolver<'a, Ctx>>, resolver: Arc<SingularResolver<'a, Ctx>>,
} }
#[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 {}
impl<'a, Ctx: Context<'a>> SingularResolver<'a, Ctx> { impl<'a, Ctx: Context<'a>> SingularResolver<'a, Ctx> {
pub fn from_mentionable<A: Mentionable<'a, Ctx>>(a: &A) -> Self { pub fn from_mentionable<A: Mentionable<'a, Ctx>>(a: &A) -> Self {
let mut points = Vec::new(); let mut points = Vec::new();

View File

@ -7,7 +7,6 @@ use sha2::{Digest, Sha256};
use crate::func::{context::*, *}; use crate::func::{context::*, *};
use crate::rcore::*; use crate::rcore::*;
use crate::rstd::singular::*;
use crate::rstd::{inject::*, typeless::*}; use crate::rstd::{inject::*, typeless::*};
pub struct NoDiagnostic; pub struct NoDiagnostic;