cross: DimSlice: allow the underlying data to be a Vec
This commit is contained in:
@@ -7,7 +7,7 @@ use crate::vec::Vec3u;
|
||||
/// use this to wrap a flat region of memory into something which can be indexed by coordinates in
|
||||
/// 3d space.
|
||||
#[cfg_attr(feature = "fmt", derive(Debug))]
|
||||
#[derive(PartialEq)]
|
||||
#[derive(Clone, PartialEq)]
|
||||
pub struct DimSlice<T> {
|
||||
dim: Vec3u,
|
||||
items: T,
|
||||
@@ -78,6 +78,42 @@ impl<'a, T: IndexMut<usize> + ?Sized> IndexMut<Vec3u> for DimSlice<&'a mut T> {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
impl<T> Index<Vec3u> for DimSlice<Vec<T>> {
|
||||
type Output=T;
|
||||
|
||||
fn index(&self, idx: Vec3u) -> &Self::Output {
|
||||
let idx = index(idx, self.dim);
|
||||
&self.items[idx]
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
impl<T> IndexMut<Vec3u> for DimSlice<Vec<T>> {
|
||||
fn index_mut(&mut self, idx: Vec3u) -> &mut Self::Output {
|
||||
let idx = index(idx, self.dim);
|
||||
&mut self.items[idx]
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
impl<T> Index<Vec3u> for DimSlice<Box<[T]>> {
|
||||
type Output=T;
|
||||
|
||||
fn index(&self, idx: Vec3u) -> &Self::Output {
|
||||
let idx = index(idx, self.dim);
|
||||
&self.items[idx]
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
impl<T> IndexMut<Vec3u> for DimSlice<Box<[T]>> {
|
||||
fn index_mut(&mut self, idx: Vec3u) -> &mut Self::Output {
|
||||
let idx = index(idx, self.dim);
|
||||
&mut self.items[idx]
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: IntoIterator> IntoIterator for DimSlice<T> {
|
||||
type Item = T::Item;
|
||||
type IntoIter = T::IntoIter;
|
||||
|
@@ -7,7 +7,7 @@ use crate::vec::Vec3u;
|
||||
|
||||
|
||||
#[cfg_attr(feature = "fmt", derive(Debug))]
|
||||
#[derive(PartialEq)]
|
||||
#[derive(Clone, PartialEq)]
|
||||
pub struct OffsetDimSlice<T> {
|
||||
offset: Vec3u,
|
||||
inner: DimSlice<T>,
|
||||
|
Reference in New Issue
Block a user