#[cfg(feature = "bytemuck")]
use core::marker::PhantomData;

#[cfg(feature = "bytemuck")]
use sled::InlineArray;

#[cfg(feature = "bytemuck")]
#[repr(transparent)]
pub struct BytesAsValSlice<Bytes, Val>(pub Bytes, pub PhantomData<Val>);

#[cfg(feature = "bytemuck")]
impl<Bytes, Val> AsRef<[Val]> for BytesAsValSlice<Bytes, Val>
where
    Val: bytemuck::AnyBitPattern,
    Bytes: AsRef<[u8]>,
{
    #[inline]
    fn as_ref(&self) -> &[Val] {
        bytemuck::cast_slice(self.0.as_ref())
    }
}

#[cfg(feature = "bytemuck")]
impl<Val: bytemuck::AnyBitPattern + bytemuck::NoUninit> AsMut<[Val]>
    for BytesAsValSlice<InlineArray, Val>
{
    #[inline]
    fn as_mut(&mut self) -> &mut [Val] {
        bytemuck::cast_slice_mut(self.0.make_mut())
    }
}
