use core::ops::Deref;
use core::slice;
#[derive(Clone, Copy, Debug)]
#[repr(transparent)]
pub struct Chunk<'a>(pub(crate) &'a [f32]);
impl Deref for Chunk<'_> {
type Target = [f32];
fn deref(&self) -> &Self::Target {
self.0
}
}
impl<'a> IntoIterator for &Chunk<'a> {
type Item = &'a f32;
type IntoIter = core::slice::Iter<'a, f32>;
fn into_iter(self) -> Self::IntoIter {
self.0.iter()
}
}
impl<'a> From<&'a [f32]> for Chunk<'a> {
fn from(slice: &'a [f32]) -> Self {
Chunk(slice)
}
}
impl<'a> From<&'a [u8]> for Chunk<'a> {
fn from(buffer: &'a [u8]) -> Self {
Self(unsafe {
slice::from_raw_parts(
buffer.as_ptr().cast::<f32>(),
buffer.len() / size_of::<f32>(),
)
})
}
}