From 3c993aa73c93f0fe335ced78d9709b39cdbd1935 Mon Sep 17 00:00:00 2001 From: HampusM Date: Sun, 6 Nov 2022 14:06:22 +0100 Subject: refactor: improve cast error handling --- src/libs/intertrait/cast/rc.rs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'src/libs/intertrait/cast/rc.rs') diff --git a/src/libs/intertrait/cast/rc.rs b/src/libs/intertrait/cast/rc.rs index 805bcd7..ec70544 100644 --- a/src/libs/intertrait/cast/rc.rs +++ b/src/libs/intertrait/cast/rc.rs @@ -30,12 +30,13 @@ impl CastRc for CastFromSelf self: Rc, ) -> Result, CastError> { - let caster = - get_caster::((*self).type_id()).ok_or(CastError::CastFailed { - from: type_name::(), - to: type_name::(), - })?; + let caster = get_caster::((*self).type_id()) + .map_err(CastError::GetCasterFailed)?; - Ok((caster.cast_rc)(self.rc_any())) + (caster.cast_rc)(self.rc_any()).map_err(|err| CastError::CastFailed { + source: err, + from: type_name::(), + to: type_name::(), + }) } } -- cgit v1.2.3-18-g5258