aboutsummaryrefslogtreecommitdiff
path: root/src/libs
diff options
context:
space:
mode:
Diffstat (limited to 'src/libs')
-rw-r--r--src/libs/intertrait/cast/arc.rs23
-rw-r--r--src/libs/intertrait/cast/box.rs10
-rw-r--r--src/libs/intertrait/cast/rc.rs10
3 files changed, 20 insertions, 23 deletions
diff --git a/src/libs/intertrait/cast/arc.rs b/src/libs/intertrait/cast/arc.rs
index 33d84d2..1742c32 100644
--- a/src/libs/intertrait/cast/arc.rs
+++ b/src/libs/intertrait/cast/arc.rs
@@ -31,19 +31,16 @@ impl<CastFromSelf: ?Sized + CastFromSync> CastArc for CastFromSelf
self: Arc<Self>,
) -> Result<Arc<OtherTrait>, CastError>
{
- let caster = get_caster::<OtherTrait>((*self).type_id()).map_or_else(
- || {
- Err(CastError::CastFailed {
- from: type_name::<CastFromSelf>(),
- to: type_name::<OtherTrait>(),
- })
- },
- Ok,
- )?;
+ let caster =
+ get_caster::<OtherTrait>((*self).type_id()).ok_or(CastError::CastFailed {
+ from: type_name::<CastFromSelf>(),
+ to: type_name::<OtherTrait>(),
+ })?;
- match caster.opt_cast_arc {
- Some(cast_arc) => Ok(cast_arc(self.arc_any())),
- None => Err(CastError::NotArcCastable(type_name::<OtherTrait>())),
- }
+ let cast_arc = caster
+ .opt_cast_arc
+ .ok_or(CastError::NotArcCastable(type_name::<OtherTrait>()))?;
+
+ Ok(cast_arc(self.arc_any()))
}
}
diff --git a/src/libs/intertrait/cast/box.rs b/src/libs/intertrait/cast/box.rs
index c463c2f..5694d97 100644
--- a/src/libs/intertrait/cast/box.rs
+++ b/src/libs/intertrait/cast/box.rs
@@ -30,12 +30,12 @@ impl<CastFromSelf: ?Sized + CastFrom> CastBox for CastFromSelf
self: Box<Self>,
) -> Result<Box<OtherTrait>, CastError>
{
- match get_caster::<OtherTrait>((*self).type_id()) {
- Some(caster) => Ok((caster.cast_box)(self.box_any())),
- None => Err(CastError::CastFailed {
+ let caster =
+ get_caster::<OtherTrait>((*self).type_id()).ok_or(CastError::CastFailed {
from: type_name::<CastFromSelf>(),
to: type_name::<OtherTrait>(),
- }),
- }
+ })?;
+
+ Ok((caster.cast_box)(self.box_any()))
}
}
diff --git a/src/libs/intertrait/cast/rc.rs b/src/libs/intertrait/cast/rc.rs
index 63c0024..805bcd7 100644
--- a/src/libs/intertrait/cast/rc.rs
+++ b/src/libs/intertrait/cast/rc.rs
@@ -30,12 +30,12 @@ impl<CastFromSelf: ?Sized + CastFrom> CastRc for CastFromSelf
self: Rc<Self>,
) -> Result<Rc<OtherTrait>, CastError>
{
- match get_caster::<OtherTrait>((*self).type_id()) {
- Some(caster) => Ok((caster.cast_rc)(self.rc_any())),
- None => Err(CastError::CastFailed {
+ let caster =
+ get_caster::<OtherTrait>((*self).type_id()).ok_or(CastError::CastFailed {
from: type_name::<CastFromSelf>(),
to: type_name::<OtherTrait>(),
- }),
- }
+ })?;
+
+ Ok((caster.cast_rc)(self.rc_any()))
}
}