• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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