xref: /aosp_15_r20/external/mesa3d/src/gallium/frontends/rusticl/util/serialize.rs (revision 6104692788411f58d303aa86923a9ff6ecaded22)
1 /// Casts a &[T] to a [&u8] without copying.
2 /// Inspired by cast_slice from the bytemuck crate. Drop this copy once external crates are supported.
3 ///
4 /// # Safety
5 ///
6 /// T must not contain any uninitialized bytes such as padding.
7 #[inline]
as_byte_slice<T>(t: &[T]) -> &[u8]8 pub unsafe fn as_byte_slice<T>(t: &[T]) -> &[u8] {
9     let new_len = core::mem::size_of_val(t) / core::mem::size_of::<u8>();
10     unsafe { core::slice::from_raw_parts(t.as_ptr().cast(), new_len) }
11 }
12