Array

Struct Array 

Source
pub struct Array<T, const D: usize, A: Allocator = Global> { /* private fields */ }

Implementations§

Source§

impl<T: Default + Clone, const D: usize> Array<T, D>

Source

pub fn new(size: [usize; D]) -> Self

Source§

impl<T: Clone, const D: usize> Array<T, D>

Source

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
Hide additional 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>

Source

pub fn new_by<F: Fn() -> T>(size: [usize; D], supplier: F) -> Self

Source

pub fn new_by_enumeration<F: Fn(usize) -> T>( size: [usize; D], supplier: F, ) -> Self

Source

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

pub fn from_flat(array: Vec<T>, size: [usize; D]) -> Option<Self>

Reinterprets a 1D array as an ND 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>

Source

pub fn size(&self) -> [usize; D]

Source

pub fn get(&'a self, loc: [usize; D]) -> Option<&'a T>

Source

pub unsafe fn get_unchecked(&'a self, loc: [usize; D]) -> &'a T

Source

pub fn get_mut(&'a mut self, loc: [usize; D]) -> Option<&'a mut T>

Source

pub unsafe fn get_unchecked_mut(&'a mut self, loc: [usize; D]) -> &'a mut T

Source

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}
Source

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}
Source

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.

Source

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<'a, T, const D: usize> Accessor<T, [usize; D]> for Array<T, D>

Source§

fn get<'b>(&'b self, index: [usize; D]) -> Option<&'b T>

Gets an item out of the array. This maybe be a split array, in which case the operation will take an item out of the vector.
Source§

impl<'a, T, const D: usize> AccessorMut<T, [usize; D]> for Array<T, D>

Source§

fn get_mut<'b>(&'b mut self, index: [usize; D]) -> Option<&'b mut T>

Gets an item out of the array mutably. This maybe be a split array, in which case the operation will take an item out of the vector.
Source§

impl<T: Clone, const D: usize, A: Clone + Allocator> Clone for Array<T, D, A>

Source§

fn clone(&self) -> Array<T, D, A>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T, const D: usize> Index<[usize; D]> for Array<T, D>

Source§

type Output = T

The returned type after indexing.
Source§

fn index(&self, index: [usize; D]) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl<T, const D: usize> IndexMut<[usize; D]> for Array<T, D>

Source§

fn index_mut(&mut self, index: [usize; D]) -> &mut T

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl<T, const D: usize, V: RawVector<T, D>> SizedVectorArray<T, D, V, [usize; D]> for Array<V, D>

Source§

fn ptr(&self) -> *const V

Source§

fn ptr_mut(&mut self) -> *mut V

Source§

fn len(&self) -> usize

Source§

fn convert_index(&self, index: [usize; D]) -> usize

Please make this inline for speed
Source§

fn is_empty(&self) -> bool

Source§

fn vec_split_fast<'a>(&'a self) -> [FastAccessor<'a, T, D, V, I, Self>; D]

Source§

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>

Source§

fn get<'a>(&'a self, index: [usize; D]) -> Option<&'a V>

Source§

fn get_mut<'a>(&'a mut self, index: [usize; D]) -> Option<&'a mut V>

Source§

fn vec_split_safe<'a>(&'a self) -> [SafeAccessor<'a, T, D, V, I, Self>; D]

Source§

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>

§

impl<T, const D: usize, A> Send for Array<T, D, A>
where A: Send, T: Send,

§

impl<T, const D: usize, A> Sync for Array<T, D, A>
where A: Sync, T: Sync,

§

impl<T, const D: usize, A> Unpin for Array<T, D, A>
where A: Unpin, T: Unpin,

§

impl<T, const D: usize, A> UnwindSafe for Array<T, D, A>
where A: UnwindSafe, T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.