use std::ops::{Deref, DerefMut};
use std::ptr::{slice_from_raw_parts, slice_from_raw_parts_mut};
#[repr(align(128))]
pub struct AlignedBytes<const N: usize>([u8; N]);
impl<const N: usize> AlignedBytes<N> {
#[inline]
pub const fn new() -> AlignedBytes<N> {
Self([0; N])
}
}
impl<const N: usize> Default for AlignedBytes<N> {
#[inline]
fn default() -> Self {
Self::new()
}
}
impl<const N: usize> Deref for AlignedBytes<N> {
type Target = [u8];
#[inline]
fn deref(&self) -> &Self::Target {
unsafe { &*slice_from_raw_parts(self.0.as_ptr(), N) }
}
}
impl<const N: usize> DerefMut for AlignedBytes<N> {
#[inline]
fn deref_mut(&mut self) -> &mut Self::Target {
unsafe { &mut *slice_from_raw_parts_mut(self.0.as_mut_ptr(), N) }
}
}