use std::mem::MaybeUninit; pub trait MaybeUninitByteSlice { unsafe fn cast(&self) -> &[Item]; } impl MaybeUninitByteSlice for &[MaybeUninit] { unsafe fn cast(&self) -> &[Item] { assert_eq!(self.len() % size_of::(), 0, "Invalid item size"); assert_eq!( self.as_ptr().addr() % align_of::(), 0, "Invalid item alignment" ); let new_len = self.len() / size_of::(); if new_len == 0 { return &[]; } unsafe { std::slice::from_raw_parts(self.as_ptr().cast::(), new_len) } } }