make SingularRobust default
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 20:42:52 +00:00
parent 0814215594
commit e8c2ec739d
2 changed files with 2 additions and 21 deletions

View File

@ -21,10 +21,6 @@ pub struct SingularResolver<'a, Ctx: Context<'a>> {
points: Vec<Arc<dyn SingularResolution<'a, Ctx>>>, points: Vec<Arc<dyn SingularResolution<'a, Ctx>>>,
} }
struct SingularRobust<'a, Ctx: Context<'a>> {
resolver: Arc<SingularResolver<'a, Ctx>>,
}
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();
@ -53,26 +49,11 @@ impl<'a, Ctx: Context<'a>> SingularResolver<'a, Ctx> {
Ok(point.clone().singular()) Ok(point.clone().singular())
} }
} }
pub fn robust(self) -> Arc<dyn Resolver<'a, Ctx>> {
SingularRobust {
resolver: self.into(),
}
.into_rc()
}
} }
impl<'a, Ctx: Context<'a>> Resolver<'a, Ctx> for SingularResolver<'a, Ctx> { impl<'a, Ctx: Context<'a>> Resolver<'a, Ctx> for SingularResolver<'a, Ctx> {
fn resolve(self: Arc<Self>, address: Address) -> HashResolution<'a, Ctx> { fn resolve(self: Arc<Self>, address: Address) -> HashResolution<'a, Ctx> {
self.resolve_robust(address).unwrap() self.resolve_robust(address)
}
}
impl<'a, Ctx: Context<'a>> Resolver<'a, Ctx> for SingularRobust<'a, Ctx> {
fn resolve(self: Arc<Self>, address: Address) -> HashResolution<'a, Ctx> {
self.resolver
.clone()
.resolve_robust(address)
.map_err(SingularError::into) .map_err(SingularError::into)
.map_err(Err) .map_err(Err)
.unwrap_or_else(Ctx::pure) .unwrap_or_else(Ctx::pure)

View File

@ -8,7 +8,7 @@ pub trait CastMentionable<'a, Ctx: Context<'a>>: Mentionable<'a, Ctx> {
fn m_cast<A: Mentionable<'a, Ctx>>(&self, factory: &Fctr<'a, A>) -> ParseResultA<'a, A> { fn m_cast<A: Mentionable<'a, Ctx>>(&self, factory: &Fctr<'a, A>) -> ParseResultA<'a, A> {
factory.parse_slice( factory.parse_slice(
&self.bytes(), &self.bytes(),
&SingularResolver::from_mentionable(self).robust(), &SingularResolver::from_mentionable(self).into_rc(),
) )
} }
} }