pub struct Array<T, const D: usize, A: Allocator = Global> { /* private fields */ }Implementations§
Source§impl<T: Clone, const D: usize> Array<T, D>
impl<T: Clone, const D: usize> Array<T, D>
Sourcepub fn new_with(size: [usize; D], item: T) -> Self
pub fn new_with(size: [usize; D], item: T) -> Self
Examples found in repository?
examples/indexing.rs (line 4)
3fn main() {
4 let mut array = Array::new_with([2, 2], 0);
5 array[[0, 0]] = 1;
6 array[[1, 0]] = 2;
7 array[[0, 1]] = 3;
8 array[[1, 1]] = 4;
9 for y in 0..2 {
10 for x in 0..2 {
11 print!("{}", array[[x, y]]);
12 }
13 println!();
14 }
15}More examples
examples/iterators.rs (line 4)
3fn main() {
4 let mut array = Array::new_with([5, 4], 0);
5 array
6 .iter_mut()
7 .filter(|(loc, _)| loc[0] == 1)
8 .for_each(|x| {
9 println!("{x:?}");
10 *x.1 += x.0[1];
11 });
12 for y in 0..4 {
13 for x in 0..5 {
14 print!("{}", array[[x, y]]);
15 }
16 println!();
17 }
18 assert_eq!(
19 array.iter().map(|x| *x.1).collect::<Vec<_>>(),
20 vec![0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 2, 0, 0, 0, 0, 3, 0, 0, 0]
21 )
22}Source§impl<T, const D: usize> Array<T, D>
impl<T, const D: usize> Array<T, D>
pub fn new_by<F: Fn() -> T>(size: [usize; D], supplier: F) -> Self
pub fn new_by_enumeration<F: Fn(usize) -> T>( size: [usize; D], supplier: F, ) -> Self
Sourcepub fn into_flattened(self) -> Vec<T>
pub fn into_flattened(self) -> Vec<T>
Flattens the ND Array into a 1D Array with indexing x + y * size_x + z * size_x * size_y etc. This is a zero-cost operation.
Source§impl<'a, T, const D: usize, A: Allocator> Array<T, D, A>
impl<'a, T, const D: usize, A: Allocator> Array<T, D, A>
pub fn size(&self) -> [usize; D]
pub fn get(&'a self, loc: [usize; D]) -> Option<&'a T>
pub unsafe fn get_unchecked(&'a self, loc: [usize; D]) -> &'a T
pub fn get_mut(&'a mut self, loc: [usize; D]) -> Option<&'a mut T>
pub unsafe fn get_unchecked_mut(&'a mut self, loc: [usize; D]) -> &'a mut T
Sourcepub fn iter(&self) -> Iter<Iter<'_, T>, D>
pub fn iter(&self) -> Iter<Iter<'_, T>, D>
Examples found in repository?
examples/iterators.rs (line 19)
3fn main() {
4 let mut array = Array::new_with([5, 4], 0);
5 array
6 .iter_mut()
7 .filter(|(loc, _)| loc[0] == 1)
8 .for_each(|x| {
9 println!("{x:?}");
10 *x.1 += x.0[1];
11 });
12 for y in 0..4 {
13 for x in 0..5 {
14 print!("{}", array[[x, y]]);
15 }
16 println!();
17 }
18 assert_eq!(
19 array.iter().map(|x| *x.1).collect::<Vec<_>>(),
20 vec![0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 2, 0, 0, 0, 0, 3, 0, 0, 0]
21 )
22}Sourcepub fn iter_mut(&mut self) -> Iter<IterMut<'_, T>, D>
pub fn iter_mut(&mut self) -> Iter<IterMut<'_, T>, D>
Examples found in repository?
examples/iterators.rs (line 6)
3fn main() {
4 let mut array = Array::new_with([5, 4], 0);
5 array
6 .iter_mut()
7 .filter(|(loc, _)| loc[0] == 1)
8 .for_each(|x| {
9 println!("{x:?}");
10 *x.1 += x.0[1];
11 });
12 for y in 0..4 {
13 for x in 0..5 {
14 print!("{}", array[[x, y]]);
15 }
16 println!();
17 }
18 assert_eq!(
19 array.iter().map(|x| *x.1).collect::<Vec<_>>(),
20 vec![0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 2, 0, 0, 0, 0, 3, 0, 0, 0]
21 )
22}Sourcepub fn as_flattened(&self) -> &[T]
pub fn as_flattened(&self) -> &[T]
Flattens the ND Array into a 1D Array with indexing x + y * size_x + z * size_x * size_y etc. This is a zero-cost operation.
Sourcepub fn as_flattened_mut(&mut self) -> &mut [T]
pub fn as_flattened_mut(&mut self) -> &mut [T]
Flattens the ND Array into a 1D Array with indexing x + y * size_x + z * size_x * size_y etc. This is a zero-cost operation.
Trait Implementations§
Source§impl<T, const D: usize, V: RawVector<T, D>> SizedVectorArray<T, D, V, [usize; D]> for Array<V, D>
impl<T, const D: usize, V: RawVector<T, D>> SizedVectorArray<T, D, V, [usize; D]> for Array<V, D>
fn ptr(&self) -> *const V
fn ptr_mut(&mut self) -> *mut V
fn len(&self) -> usize
fn is_empty(&self) -> bool
fn vec_split_fast<'a>(&'a self) -> [FastAccessor<'a, T, D, V, I, Self>; D]
fn vec_split_fast_mut<'a>( &'a mut self, ) -> [FastAccessorMut<'a, T, D, V, I, Self>; D]
Source§impl<T, const D: usize, V: Vector<T, D>> VectorArray<T, D, V, [usize; D]> for Array<V, D>
impl<T, const D: usize, V: Vector<T, D>> VectorArray<T, D, V, [usize; D]> for Array<V, D>
fn get<'a>(&'a self, index: [usize; D]) -> Option<&'a V>
fn get_mut<'a>(&'a mut self, index: [usize; D]) -> Option<&'a mut V>
fn vec_split_safe<'a>(&'a self) -> [SafeAccessor<'a, T, D, V, I, Self>; D]
fn vec_split_safe_mut<'a>( &'a mut self, ) -> [SafeAccessorMut<'a, T, D, V, I, Self>; D]
Auto Trait Implementations§
impl<T, const D: usize, A> Freeze for Array<T, D, A>
impl<T, const D: usize, A> RefUnwindSafe for Array<T, D, A>where
A: RefUnwindSafe,
T: RefUnwindSafe,
impl<T, const D: usize, A> Send for Array<T, D, A>
impl<T, const D: usize, A> Sync for Array<T, D, A>
impl<T, const D: usize, A> Unpin for Array<T, D, A>
impl<T, const D: usize, A> UnwindSafe for Array<T, D, A>where
A: UnwindSafe,
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more