use crate::Zip;
use crate::traits::Array2dStorageMut;
use crate::{Array2d, GenericArray2d, traits::Array2dStorage, zip::GenericArray2dRef};
impl<T: Array2dStorage> GenericArray2d<T> {
pub fn copied(&self) -> Array2d<T::Item>
where
T::Item: Copy,
{
let mut data = Vec::with_capacity(self.len());
data.extend(self.values().copied());
Array2d {
data,
boundary: self.boundary,
pitch: self.pitch,
}
}
pub fn cloned(&self) -> Array2d<T::Item>
where
T::Item: Clone,
{
let mut data = Vec::with_capacity(self.len());
data.extend(self.values().cloned());
Array2d {
data,
boundary: self.boundary,
pitch: self.pitch,
}
}
pub fn mapped<U>(&self, f: impl FnMut(&T::Item) -> U) -> Array2d<U> {
let mut data = Vec::with_capacity(self.len());
data.extend(self.values().map(f));
Array2d {
data,
boundary: self.boundary,
pitch: self.pitch,
}
}
pub fn zip<U: GenericArray2dRef>(&self, rhs: U) -> Zip<&Self, U> {
Zip(self, rhs)
}
pub fn zip_mut<U: GenericArray2dRef>(&mut self, rhs: U) -> Zip<&mut Self, U>
where
T: Array2dStorageMut,
{
Zip(self, rhs)
}
}