use crate::depot::index::{bitmap, bitmap::entry::Row};
pub unsafe trait Words<W: bitmap::Width = usize> {
type Plane: Copy;
type Size: Copy + Into<u32>;
fn shape(&self) -> bitmap::Shape<Self::Size, W>;
fn words(&self, plane: Self::Plane) -> &[bitmap::Word<W>];
fn row(entry: Row<&Self, (), (), W>, plane: Self::Plane) -> &[bitmap::Word<W>]
where
Self: Sized,
{
(*entry.source()).words(plane)
}
}
unsafe impl<W: bitmap::Width, S: Words<W>> Words<W> for &S {
type Plane = S::Plane;
type Size = S::Size;
fn shape(&self) -> bitmap::Shape<Self::Size, W> {
S::shape(self)
}
fn words(&self, plane: Self::Plane) -> &[bitmap::Word<W>] {
S::words(self, plane)
}
fn row(entry: Row<&Self, (), (), W>, plane: Self::Plane) -> &[bitmap::Word<W>] {
S::row(unsafe { entry.map(|source| *source) }, plane)
}
}
unsafe impl<W: bitmap::Width, S: Words<W>> Words<W> for &mut S {
type Plane = S::Plane;
type Size = S::Size;
fn shape(&self) -> bitmap::Shape<Self::Size, W> {
S::shape(self)
}
fn words(&self, plane: Self::Plane) -> &[bitmap::Word<W>] {
S::words(self, plane)
}
fn row(entry: Row<&Self, (), (), W>, plane: Self::Plane) -> &[bitmap::Word<W>] {
S::row(unsafe { entry.map(|source| &**source) }, plane)
}
}