From f08b7d3c7a5478582d4398e43effe84dcb873107 Mon Sep 17 00:00:00 2001 From: timofey <tim@ongoteam.yaconnect.com> Date: Tue, 1 Aug 2023 20:55:38 +0000 Subject: [PATCH] `cast_error` --- src/rstd/cast.rs | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/src/rstd/cast.rs b/src/rstd/cast.rs index 8cfdba4..36135ca 100644 --- a/src/rstd/cast.rs +++ b/src/rstd/cast.rs @@ -169,20 +169,33 @@ impl<'a, Ctx: CastCtx<'a>> TypelessMentionable<'a, Ctx> { } } -fn cast_resolve<'a, Ctx: CastCtx<'a>, A: Mentionable<'a, Ctx>>( - typeless_origin: Rc<dyn Origin<'a, Ctx, Mtbl = TypelessMentionable<'a, Ctx>>>, +fn cast_error<'a, Ctx: CastCtx<'a>, A: Mentionable<'a, Ctx>>( + error: ResolutionFailure<'a, Ctx, TypelessMentionable<'a, Ctx>>, +) -> ResolutionFailure<'a, Ctx, A> { + ResolutionError::Lookup(match error { + ResolutionError::Lookup(lookup_error) => lookup_error, + ResolutionError::Parse(parse_error) => Ctx::from_cast(CastError::Typeless(parse_error)), + }) +} + +fn cast_resolved<'a, Ctx: CastCtx<'a>, A: Mentionable<'a, Ctx>>( + resolved: ResolutionResult<'a, Ctx, TypelessMentionable<'a, Ctx>>, factory: A::Fctr, -) -> Resolution<'a, Ctx, A> { - typeless_origin.resolve_map(|resolved| match resolved { +) -> ResolutionResult<'a, Ctx, A> { + match resolved { Ok(typeless_mentionable) => match typeless_mentionable.cast(factory) { Ok(mentionable) => Ok(Rc::new(mentionable)), Err(parse_error) => Err(ResolutionError::Parse(parse_error)), }, - Err(error) => Err(ResolutionError::Lookup(match error { - ResolutionError::Lookup(lookup_error) => lookup_error, - ResolutionError::Parse(parse_error) => Ctx::from_cast(CastError::Typeless(parse_error)), - })), - }) + Err(error) => Err(cast_error::<Ctx, A>(error)), + } +} + +fn cast_resolve<'a, Ctx: CastCtx<'a>, A: Mentionable<'a, Ctx>>( + typeless_origin: Rc<dyn Origin<'a, Ctx, Mtbl = TypelessMentionable<'a, Ctx>>>, + factory: A::Fctr, +) -> Resolution<'a, Ctx, A> { + typeless_origin.resolve_map(|resolved| cast_resolved(resolved, factory)) } fn cast_origin<'a, Ctx: CastCtx<'a>, A: Mentionable<'a, Ctx>>(