diff options
| author | HampusM <hampus@hampusmat.com> | 2022-11-03 21:15:24 +0100 | 
|---|---|---|
| committer | HampusM <hampus@hampusmat.com> | 2022-11-03 21:15:24 +0100 | 
| commit | e665c2a3ca9b15f406c8e12e4a7ab372fcad4d36 (patch) | |
| tree | 45e2d26cbaf76ba7714911dcdf1495759858ed78 /src/libs/intertrait/cast/arc.rs | |
| parent | 488faf96336711a527a3610c728a2409087b69fa (diff) | |
refactor: improve readability of cast functions
Diffstat (limited to 'src/libs/intertrait/cast/arc.rs')
| -rw-r--r-- | src/libs/intertrait/cast/arc.rs | 23 | 
1 files changed, 10 insertions, 13 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()))      }  }  | 
