diff options
Diffstat (limited to 'src/libs/intertrait/cast/box.rs')
-rw-r--r-- | src/libs/intertrait/cast/box.rs | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/src/libs/intertrait/cast/box.rs b/src/libs/intertrait/cast/box.rs index 5694d97..67fd949 100644 --- a/src/libs/intertrait/cast/box.rs +++ b/src/libs/intertrait/cast/box.rs @@ -30,12 +30,13 @@ impl<CastFromSelf: ?Sized + CastFrom> CastBox for CastFromSelf self: Box<Self>, ) -> Result<Box<OtherTrait>, CastError> { - let caster = - get_caster::<OtherTrait>((*self).type_id()).ok_or(CastError::CastFailed { - from: type_name::<CastFromSelf>(), - to: type_name::<OtherTrait>(), - })?; + let caster = get_caster::<OtherTrait>((*self).type_id()) + .map_err(CastError::GetCasterFailed)?; - Ok((caster.cast_box)(self.box_any())) + (caster.cast_box)(self.box_any()).map_err(|err| CastError::CastFailed { + source: err, + from: type_name::<Self>(), + to: type_name::<OtherTrait>(), + }) } } |