diff --git a/utils/src/cast.rs b/utils/src/cast.rs index 61c3d4124..38406aafd 100644 --- a/utils/src/cast.rs +++ b/utils/src/cast.rs @@ -9,11 +9,13 @@ use std::any::TypeId; use std::mem::size_of; +/// Returns true if two types are in fact the same type. #[inline(always)] pub fn same_type() -> bool { TypeId::of::() == TypeId::of::() && size_of::() == size_of::() } +/// Cast a reference if the types are equal, such as from a specific type to a generic that it implements. #[inline(always)] pub fn cast_ref(u: &U) -> Option<&V> { if same_type::() { @@ -23,6 +25,7 @@ pub fn cast_ref(u: &U) -> Option<&V> { } } +/// Cast a reference if the types are equal, such as from a specific type to a generic that it implements. #[inline(always)] pub fn cast_mut(u: &mut U) -> Option<&mut V> { if same_type::() {