Add IndexMut impls for MatBuf

This commit is contained in:
tali 2022-12-21 20:56:38 -05:00
parent 13f5d0c2eb
commit b6e6a00164
1 changed files with 27 additions and 0 deletions

View File

@ -245,6 +245,15 @@ where
}
}
impl<T> core::ops::IndexMut<core::ops::RangeFull> for MatBuf<T>
where
T: AsRef<[u16]> + AsMut<[u16]>,
{
fn index_mut(&mut self, _: core::ops::RangeFull) -> &mut [u16] {
&mut self.buffer.as_mut()[..self.rows]
}
}
// All boilerplate below
impl<T: AsRef<[u16]>> core::ops::Deref for MatBuf<T> {
@ -274,6 +283,24 @@ impl<T: AsRef<[u16]>, U: AsRef<[u16]>> core::cmp::PartialEq<MatBuf<U>> for MatBu
self.as_mat() == other.as_mat()
}
}
impl<T: AsRef<[u16]>> core::ops::Index<core::ops::RangeFull> for MatBuf<T> {
type Output = [u16];
fn index(&self, _: core::ops::RangeFull) -> &[u16] {
&self.as_mat()[..]
}
}
impl<T: AsRef<[u16]> + AsMut<[u16]>> core::ops::IndexMut<core::ops::Range<i16>> for MatBuf<T> {
fn index_mut(&mut self, r: core::ops::Range<i16>) -> &mut [u16] {
let ar = self.to_array_range(r);
&mut self.buffer.as_mut()[ar]
}
}
impl<T: AsRef<[u16]>> core::ops::Index<core::ops::Range<i16>> for MatBuf<T> {
type Output = [u16];
fn index(&self, r: core::ops::Range<i16>) -> &[u16] {
&self.as_mat()[r]
}
}
#[cfg(test)]
mod test {