simplify reborrow

This commit is contained in:
Lokathor 2019-09-20 00:32:35 -06:00
parent 22e1b7a6f6
commit 2b8ef93dee

View File

@ -158,11 +158,7 @@ pub fn try_cast_ref<A: Pod, B: Pod>(a: &A) -> Result<&B, PodCastError> {
if align_of::<B>() > align_of::<A>() && (a as *const A as usize) % align_of::<B>() != 0 {
Err(PodCastError::TargetAlignmentGreaterAndInputNotAligned)
} else if size_of::<B>() == size_of::<A>() {
Ok(unsafe {
(a as *const A as *const B)
.as_ref()
.unwrap_or_else(|| core::hint::unreachable_unchecked())
})
Ok(unsafe { &*(a as *const A as *const B) })
} else {
Err(PodCastError::SizeMismatch)
}