remove SingularCtx
This commit is contained in:
parent
ae95e99767
commit
0814215594
@ -6,7 +6,7 @@ pub trait Context<'a>: FallibleCtx<'a> + MonadContext<'a> + Send + Sync {
|
||||
type D: Diagnostic<'a, Self::T>;
|
||||
|
||||
/// Type to represent resolution errors mainly arising in [`Resolver::resolve`].
|
||||
type LookupError: 'a + Send + Error;
|
||||
type LookupError: 'a + Send + Error + From<SingularError>;
|
||||
|
||||
/// Get [type@Hash] of a slice, mostly for use in [`Point`].
|
||||
fn hash(s: &[u8]) -> Hash;
|
||||
|
@ -54,10 +54,7 @@ impl<'a, Ctx: Context<'a>> SingularResolver<'a, Ctx> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn robust(self) -> Arc<dyn Resolver<'a, Ctx>>
|
||||
where
|
||||
Ctx: SingularCtx<'a>,
|
||||
{
|
||||
pub fn robust(self) -> Arc<dyn Resolver<'a, Ctx>> {
|
||||
SingularRobust {
|
||||
resolver: self.into(),
|
||||
}
|
||||
@ -71,25 +68,12 @@ impl<'a, Ctx: Context<'a>> Resolver<'a, Ctx> for SingularResolver<'a, Ctx> {
|
||||
}
|
||||
}
|
||||
|
||||
pub trait SingularCtx<'a>: Context<'a> {
|
||||
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: 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(Ctx::from_singular)
|
||||
.map_err(SingularError::into)
|
||||
.map_err(Err)
|
||||
.unwrap_or_else(Ctx::pure)
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ use crate::rcore::*;
|
||||
|
||||
use super::{singular::*, *};
|
||||
|
||||
pub trait CastMentionable<'a, Ctx: SingularCtx<'a>>: Mentionable<'a, Ctx> {
|
||||
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> {
|
||||
factory.parse_slice(
|
||||
&self.bytes(),
|
||||
@ -13,14 +13,14 @@ pub trait CastMentionable<'a, Ctx: SingularCtx<'a>>: Mentionable<'a, Ctx> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, Ctx: SingularCtx<'a>, B: Mentionable<'a, Ctx>> CastMentionable<'a, Ctx> for B {}
|
||||
impl<'a, Ctx: Context<'a>, B: Mentionable<'a, Ctx>> CastMentionable<'a, Ctx> for B {}
|
||||
|
||||
struct CastedOrigin<O: ?Sized, F> {
|
||||
origin: Arc<O>,
|
||||
factory: F,
|
||||
}
|
||||
|
||||
impl<'a, Ctx: SingularCtx<'a>, O: ?Sized + Origin<'a, Ctx>, F: Factory<'a, Ctx>> Origin<'a, Ctx>
|
||||
impl<'a, Ctx: Context<'a>, O: ?Sized + Origin<'a, Ctx>, F: Factory<'a, Ctx>> Origin<'a, Ctx>
|
||||
for CastedOrigin<O, F>
|
||||
{
|
||||
type Mtbl = F::Mtbl;
|
||||
@ -50,7 +50,7 @@ impl<'a, Ctx: SingularCtx<'a>, O: ?Sized + Origin<'a, Ctx>, F: Factory<'a, Ctx>>
|
||||
}
|
||||
}
|
||||
|
||||
pub trait CastOrigin<'a, Ctx: SingularCtx<'a>>: Origin<'a, Ctx> {
|
||||
pub trait CastOrigin<'a, Ctx: Context<'a>>: Origin<'a, Ctx> {
|
||||
fn o_cast<A: Mentionable<'a, Ctx>>(
|
||||
self: &Arc<Self>,
|
||||
factory: Fctr<'a, A>,
|
||||
@ -62,13 +62,13 @@ pub trait CastOrigin<'a, Ctx: SingularCtx<'a>>: Origin<'a, Ctx> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, Ctx: SingularCtx<'a>, O: ?Sized + Origin<'a, Ctx>> CastOrigin<'a, Ctx> for O {}
|
||||
impl<'a, Ctx: Context<'a>, O: ?Sized + Origin<'a, Ctx>> CastOrigin<'a, Ctx> for O {}
|
||||
|
||||
pub trait CastPoint<'a, Ctx: SingularCtx<'a>> {
|
||||
pub trait CastPoint<'a, Ctx: Context<'a>> {
|
||||
fn p_cast<A: Mentionable<'a, Ctx>>(self, factory: Fctr<'a, A>) -> Point<'a, Ctx, A>;
|
||||
}
|
||||
|
||||
impl<'a, Ctx: SingularCtx<'a>, B: Mentionable<'a, Ctx>> CastPoint<'a, Ctx> for Point<'a, Ctx, B> {
|
||||
impl<'a, Ctx: Context<'a>, B: Mentionable<'a, Ctx>> CastPoint<'a, Ctx> for Point<'a, Ctx, B> {
|
||||
fn p_cast<A: Mentionable<'a, Ctx>>(self, factory: Fctr<'a, A>) -> Point<'a, Ctx, A> {
|
||||
Point {
|
||||
point: self.point,
|
||||
|
@ -2,7 +2,7 @@
|
||||
//!
|
||||
//! [`rcore`]: crate::rcore
|
||||
|
||||
use super::{singular::*, tcast::*, wrapped_origin::*, *};
|
||||
use super::{tcast::*, wrapped_origin::*, *};
|
||||
use crate::mode::*;
|
||||
|
||||
type TypelessSerialize<'a> = dyn 'a + Send + Sync + Fn(&mut dyn Serializer);
|
||||
@ -112,7 +112,7 @@ impl<'a, Ctx: Context<'a>> CRegularFactory<'a, Ctx> for TypelessFactory<'a, Ctx>
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, Ctx: SingularCtx<'a>> TypelessMentionable<'a, Ctx> {
|
||||
impl<'a, Ctx: Context<'a>> TypelessMentionable<'a, Ctx> {
|
||||
pub fn from_typed<A: Mentionable<'a, Ctx>>(mentionable: Arc<A>) -> Self {
|
||||
let factory = TypelessFactory::from_typed(mentionable.factory());
|
||||
let topology = mentionable.topology_hash();
|
||||
@ -126,7 +126,7 @@ impl<'a, Ctx: SingularCtx<'a>> TypelessMentionable<'a, Ctx> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, Ctx: SingularCtx<'a>, F: Factory<'a, Ctx>> Tde<'a, Ctx> for F {
|
||||
impl<'a, Ctx: Context<'a>, F: Factory<'a, Ctx>> Tde<'a, Ctx> for F {
|
||||
fn clone_box(&self) -> TdeBox<'a, Ctx> {
|
||||
Box::new(self.clone())
|
||||
}
|
||||
@ -142,7 +142,7 @@ impl<'a, Ctx: SingularCtx<'a>, F: Factory<'a, Ctx>> Tde<'a, Ctx> for F {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, Ctx: SingularCtx<'a>, F: Factory<'a, Ctx>> Tut<'a, Ctx> for F {
|
||||
impl<'a, Ctx: Context<'a>, F: Factory<'a, Ctx>> Tut<'a, Ctx> for F {
|
||||
fn clone_box(&self) -> TutBox<'a, Ctx> {
|
||||
Box::new(self.clone())
|
||||
}
|
||||
@ -165,7 +165,7 @@ impl<'a, Ctx: SingularCtx<'a>, F: Factory<'a, Ctx>> Tut<'a, Ctx> for F {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, Ctx: SingularCtx<'a>> TypelessFactory<'a, Ctx> {
|
||||
impl<'a, Ctx: Context<'a>> TypelessFactory<'a, Ctx> {
|
||||
pub fn from_typed<F: Factory<'a, Ctx>>(factory: F) -> Self {
|
||||
TypelessFactory {
|
||||
t_deserialize: Box::new(factory.clone()),
|
||||
@ -180,7 +180,7 @@ impl<'a> TypelessError<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, Ctx: SingularCtx<'a>, A: Mentionable<'a, Ctx>> Point<'a, Ctx, A> {
|
||||
impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> Point<'a, Ctx, A> {
|
||||
/// Typeless version of the point.
|
||||
pub fn typeless(&self) -> Point<'a, Ctx, TypelessMentionable<'a, Ctx>> {
|
||||
Point {
|
||||
@ -201,7 +201,7 @@ pub trait MentionableExt<'a, Ctx: Context<'a>>: Mentionable<'a, Ctx> {
|
||||
fn points_vec(&self) -> Vec<Point<'a, Ctx, TypelessMentionable<'a, Ctx>>>;
|
||||
}
|
||||
|
||||
impl<'a, Ctx: SingularCtx<'a>, A: Mentionable<'a, Ctx>> MentionableExt<'a, Ctx> for A {
|
||||
impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> MentionableExt<'a, Ctx> for A {
|
||||
fn points_typeless(&self, points: &mut Vec<Point<'a, Ctx, TypelessMentionable<'a, Ctx>>>) {
|
||||
self.points_typed(points)
|
||||
}
|
||||
@ -213,7 +213,7 @@ impl<'a, Ctx: SingularCtx<'a>, A: Mentionable<'a, Ctx>> MentionableExt<'a, Ctx>
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, Ctx: SingularCtx<'a>> PointsVisitor<'a, Ctx>
|
||||
impl<'a, Ctx: Context<'a>> PointsVisitor<'a, Ctx>
|
||||
for Vec<Point<'a, Ctx, TypelessMentionable<'a, Ctx>>>
|
||||
{
|
||||
fn visit<A: Mentionable<'a, Ctx>>(&mut self, point: &Point<'a, Ctx, A>) {
|
||||
|
Loading…
Reference in New Issue
Block a user