From 0814215594b9089f5fef50ee2fb39c3629568e56 Mon Sep 17 00:00:00 2001 From: timofey Date: Sun, 3 Sep 2023 20:41:01 +0000 Subject: [PATCH] remove `SingularCtx` --- src/rcore/context.rs | 2 +- src/rstd/singular.rs | 22 +++------------------- src/rstd/tcast.rs | 14 +++++++------- src/rstd/typeless.rs | 16 ++++++++-------- 4 files changed, 19 insertions(+), 35 deletions(-) diff --git a/src/rcore/context.rs b/src/rcore/context.rs index 3310203..40630a6 100644 --- a/src/rcore/context.rs +++ b/src/rcore/context.rs @@ -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; /// Get [type@Hash] of a slice, mostly for use in [`Point`]. fn hash(s: &[u8]) -> Hash; diff --git a/src/rstd/singular.rs b/src/rstd/singular.rs index 69a2a0c..acb7e06 100644 --- a/src/rstd/singular.rs +++ b/src/rstd/singular.rs @@ -54,10 +54,7 @@ impl<'a, Ctx: Context<'a>> SingularResolver<'a, Ctx> { } } - pub fn robust(self) -> Arc> - where - Ctx: SingularCtx<'a>, - { + pub fn robust(self) -> Arc> { 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, -{ - 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, 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) } diff --git a/src/rstd/tcast.rs b/src/rstd/tcast.rs index 144cae9..6e5d97b 100644 --- a/src/rstd/tcast.rs +++ b/src/rstd/tcast.rs @@ -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>(&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 { origin: Arc, 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 { 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>( self: &Arc, 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>(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>(self, factory: Fctr<'a, A>) -> Point<'a, Ctx, A> { Point { point: self.point, diff --git a/src/rstd/typeless.rs b/src/rstd/typeless.rs index cd22455..bac5a7d 100644 --- a/src/rstd/typeless.rs +++ b/src/rstd/typeless.rs @@ -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>(mentionable: Arc) -> 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>(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>>; } -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>>) { 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>> { fn visit>(&mut self, point: &Point<'a, Ctx, A>) {