4
0

util.rs 486 B

12345678910111213141516
  1. use core::{mem, slice};
  2. #[cfg(feature = "std")]
  3. pub(crate) use std::collections::HashMap;
  4. #[cfg(feature = "std")]
  5. pub(crate) use std::collections::HashSet;
  6. #[cfg(not(feature = "std"))]
  7. pub(crate) use hashbrown::HashMap;
  8. #[cfg(not(feature = "std"))]
  9. pub(crate) use hashbrown::HashSet;
  10. /// bytes_of converts a <T> to a byte slice
  11. pub(crate) unsafe fn bytes_of<T>(val: &T) -> &[u8] {
  12. let ptr: *const _ = val;
  13. unsafe { slice::from_raw_parts(ptr.cast(), mem::size_of_val(val)) }
  14. }