aboutsummaryrefslogtreecommitdiff
path: root/src/libs/intertrait/cast/box.rs
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2022-11-03 21:15:24 +0100
committerHampusM <hampus@hampusmat.com>2022-11-03 21:15:24 +0100
commite665c2a3ca9b15f406c8e12e4a7ab372fcad4d36 (patch)
tree45e2d26cbaf76ba7714911dcdf1495759858ed78 /src/libs/intertrait/cast/box.rs
parent488faf96336711a527a3610c728a2409087b69fa (diff)
refactor: improve readability of cast functions
Diffstat (limited to 'src/libs/intertrait/cast/box.rs')
-rw-r--r--src/libs/intertrait/cast/box.rs10
1 files changed, 5 insertions, 5 deletions
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()))
}
}