building_blocks_storage 0.7.1

Efficient storage for maps on sparse or dense, 2D and 3D integer lattices.
Documentation
use std::ops::Deref;

pub trait AsRawBytes<'a> {
    type Output: Deref<Target = [u8]>;

    fn as_raw_bytes(&'a self) -> Self::Output;
}

impl<'a, T> AsRawBytes<'a> for [T]
where
    T: 'static + Copy,
{
    type Output = &'a [u8];

    fn as_raw_bytes(&'a self) -> Self::Output {
        unsafe {
            std::slice::from_raw_parts(
                self.as_ptr() as *const u8,
                self.len() * core::mem::size_of::<T>(),
            )
        }
    }
}