util.rs 367 B

123456789101112
  1. use core::{mem, slice};
  2. #[cfg(feature = "no_std")]
  3. pub(crate) use hashbrown::HashMap;
  4. #[cfg(not(feature = "no_std"))]
  5. pub(crate) use std::collections::HashMap;
  6. /// bytes_of converts a <T> to a byte slice
  7. pub(crate) unsafe fn bytes_of<T>(val: &T) -> &[u8] {
  8. let size = mem::size_of::<T>();
  9. slice::from_raw_parts(slice::from_ref(val).as_ptr().cast(), size)
  10. }