mirror of
https://github.com/Lokathor/bytemuck.git
synced 2024-11-22 06:42:25 +00:00
simplify reborrow
This commit is contained in:
parent
22e1b7a6f6
commit
2b8ef93dee
@ -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)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user