pub struct Grid2D<T, S: Storage, const SIZE: usize> { /* private fields */ }
Expand description
A 2D grid, backed by an Array
.
Internally the elements are stored in row major order, meaning the elements of each row are stored sequentially.
Implementations§
Source§impl<T: Clone, const SIZE: usize> Grid2D<T, (), SIZE>
impl<T: Clone, const SIZE: usize> Grid2D<T, (), SIZE>
Source§impl<T: Clone, const SIZE: usize> Grid2D<T, Boxed, SIZE>
impl<T: Clone, const SIZE: usize> Grid2D<T, Boxed, SIZE>
Source§impl<T, S: Storage, const SIZE: usize> Grid2D<T, S, SIZE>
§general queries
impl<T, S: Storage, const SIZE: usize> Grid2D<T, S, SIZE>
§general queries
Sourcepub const fn get_index_unchecked(&self, col: usize, row: usize) -> usize
pub const fn get_index_unchecked(&self, col: usize, row: usize) -> usize
Translates 2D col
,row
coordinates into a 1D index.
This function doesn’t check whether the dimensions are right.
Sourcepub const fn get_coords_unchecked(&self, index: usize) -> (usize, usize)
pub const fn get_coords_unchecked(&self, index: usize) -> (usize, usize)
Sourcepub const fn chunked_capacity(&self, chunk_len: usize) -> usize
pub const fn chunked_capacity(&self, chunk_len: usize) -> usize
Returns the number of chunks (capacity()
/chunk_len
).
Sourcepub const fn chunks_per_row(&self, chunk_len: usize) -> usize
pub const fn chunks_per_row(&self, chunk_len: usize) -> usize
Returns the number of chunks per row.
Source§impl<T, S: Storage, const SIZE: usize> Grid2D<T, S, SIZE>
§single element get/set
impl<T, S: Storage, const SIZE: usize> Grid2D<T, S, SIZE>
§single element get/set
Sourcepub fn get_ref_unchecked(&self, col: usize, row: usize) -> &T
pub fn get_ref_unchecked(&self, col: usize, row: usize) -> &T
Sourcepub fn get_ref_row_order(&self, index: usize) -> Result<&T>
pub fn get_ref_row_order(&self, index: usize) -> Result<&T>
Returns a reference to the element at the given 1D index, in row major order.
§Errors
If out of bounds.
Sourcepub fn get_ref_row_order_unchecked(&self, index: usize) -> &T
pub fn get_ref_row_order_unchecked(&self, index: usize) -> &T
Returns a reference to the element at the given 1D index, in row major order.
§Panics
If out of bounds.
Sourcepub fn get_ref_col_order(&self, index: usize) -> Result<&T>
pub fn get_ref_col_order(&self, index: usize) -> Result<&T>
Returns a reference to the element at the given 1D index, in column major order.
§Errors
If out of bounds.
Sourcepub fn get_ref_col_order_unchecked(&self, index: usize) -> &T
pub fn get_ref_col_order_unchecked(&self, index: usize) -> &T
Returns a reference to the element at the given 1D index, in column major order.
§Panics
If out of bounds.
Sourcepub fn get_ref_mut_unchecked(&mut self, col: usize, row: usize) -> &mut T
pub fn get_ref_mut_unchecked(&mut self, col: usize, row: usize) -> &mut T
Sourcepub fn get_ref_mut_row_order(&mut self, index: usize) -> Result<&mut T>
pub fn get_ref_mut_row_order(&mut self, index: usize) -> Result<&mut T>
Returns a mutable reference to the element at the given 1D index, in row major order.
§Errors
If out of bounds.
Sourcepub fn get_ref_mut_row_order_unchecked(&mut self, index: usize) -> &mut T
pub fn get_ref_mut_row_order_unchecked(&mut self, index: usize) -> &mut T
Returns a mutable reference to the element at the given 1D index, in row major order.
§Panics
If out of bounds.
Sourcepub fn get_ref_mut_col_order(&mut self, index: usize) -> Result<&mut T>
pub fn get_ref_mut_col_order(&mut self, index: usize) -> Result<&mut T>
Returns a mutable reference to the element at the given 1D index, in column major order.
§Errors
If out of bounds.
Sourcepub fn get_ref_mut_col_order_unchecked(&mut self, index: usize) -> &mut T
pub fn get_ref_mut_col_order_unchecked(&mut self, index: usize) -> &mut T
Returns a mutable reference to the element at the given 1D index, in column major order.
§Panics
If out of bounds.
Sourcepub fn set_unchecked(&mut self, element: T, col: usize, row: usize)
pub fn set_unchecked(&mut self, element: T, col: usize, row: usize)
Sourcepub fn set_row_order(&mut self, element: T, index: usize) -> Result<()>
pub fn set_row_order(&mut self, element: T, index: usize) -> Result<()>
Sourcepub fn set_row_order_unchecked(&mut self, element: T, index: usize)
pub fn set_row_order_unchecked(&mut self, element: T, index: usize)
Sourcepub fn set_col_order(&mut self, element: T, index: usize) -> Result<()>
pub fn set_col_order(&mut self, element: T, index: usize) -> Result<()>
Sourcepub fn set_col_order_unchecked(&mut self, element: T, index: usize)
pub fn set_col_order_unchecked(&mut self, element: T, index: usize)
Returns a mutable reference to the element at the given 1D index, in column major order.
§Panics
If out of bounds.
Source§impl<T: Copy, S: Storage, const SIZE: usize> Grid2D<T, S, SIZE>
§single element get methods (Copy)
impl<T: Copy, S: Storage, const SIZE: usize> Grid2D<T, S, SIZE>
§single element get methods (Copy)
Sourcepub fn get(&self, col: usize, row: usize) -> Result<T>
pub fn get(&self, col: usize, row: usize) -> Result<T>
Returns the element at the given row
and col
umn.
Sourcepub fn get_unchecked(&self, col: usize, row: usize) -> T
pub fn get_unchecked(&self, col: usize, row: usize) -> T
Sourcepub fn get_row_order(&self, index: usize) -> Result<T>
pub fn get_row_order(&self, index: usize) -> Result<T>
Returns the element at the given 1D index, in row major order.
Sourcepub fn get_row_order_unchecked(&self, index: usize) -> T
pub fn get_row_order_unchecked(&self, index: usize) -> T
Sourcepub fn get_col_order(&self, index: usize) -> Result<T>
pub fn get_col_order(&self, index: usize) -> Result<T>
Returns the element at the given 1D index, in column major order.
Sourcepub fn get_col_order_unchecked(&self, index: usize) -> T
pub fn get_col_order_unchecked(&self, index: usize) -> T
Source§impl<T, S: Storage, const SIZE: usize> Grid2D<T, S, SIZE>
§iterators
impl<T, S: Storage, const SIZE: usize> Grid2D<T, S, SIZE>
§iterators
Sourcepub fn iter_ref(&self) -> impl DoubleEndedIterator<Item = &T>
pub fn iter_ref(&self) -> impl DoubleEndedIterator<Item = &T>
Returns an iterator over references to all elements in row major order.
Sourcepub fn iter_ref_mut(&mut self) -> impl DoubleEndedIterator<Item = &mut T>
pub fn iter_ref_mut(&mut self) -> impl DoubleEndedIterator<Item = &mut T>
Returns an iterator over mutable references to all elements in row major order.
Sourcepub fn row_iter_ref(
&self,
row: usize,
) -> Result<impl DoubleEndedIterator<Item = &T>>
pub fn row_iter_ref( &self, row: usize, ) -> Result<impl DoubleEndedIterator<Item = &T>>
Returns an iterator over references to all elements in the given row.
Sourcepub fn row_iter_ref_unchecked(
&self,
row: usize,
) -> impl DoubleEndedIterator<Item = &T>
pub fn row_iter_ref_unchecked( &self, row: usize, ) -> impl DoubleEndedIterator<Item = &T>
Sourcepub fn row_iter_ref_mut(
&mut self,
row: usize,
) -> Result<impl DoubleEndedIterator<Item = &mut T>>
pub fn row_iter_ref_mut( &mut self, row: usize, ) -> Result<impl DoubleEndedIterator<Item = &mut T>>
Returns an iterator over mutable references to all elements in the given row.
Sourcepub fn row_iter_ref_mut_unchecked(
&mut self,
row: usize,
) -> impl DoubleEndedIterator<Item = &mut T>
pub fn row_iter_ref_mut_unchecked( &mut self, row: usize, ) -> impl DoubleEndedIterator<Item = &mut T>
Returns an iterator over mutable references to all elements in the given row.
§Panics
If out of bounds.
Sourcepub fn col_iter_ref(&self, col: usize) -> Result<impl Iterator<Item = &T>>
pub fn col_iter_ref(&self, col: usize) -> Result<impl Iterator<Item = &T>>
Returns an iterator over references to all elements in the given col
umn.
Sourcepub fn col_iter_ref_unchecked(&self, col: usize) -> impl Iterator<Item = &T>
pub fn col_iter_ref_unchecked(&self, col: usize) -> impl Iterator<Item = &T>
Sourcepub fn col_iter_ref_mut(
&mut self,
col: usize,
) -> Result<impl Iterator<Item = &mut T>>
pub fn col_iter_ref_mut( &mut self, col: usize, ) -> Result<impl Iterator<Item = &mut T>>
Returns an iterator over references to all elements in the given col
umn.
Sourcepub fn col_iter_ref_mut_unchecked(
&mut self,
col: usize,
) -> impl Iterator<Item = &mut T>
pub fn col_iter_ref_mut_unchecked( &mut self, col: usize, ) -> impl Iterator<Item = &mut T>
Sourcepub fn rows_iter_ref(
&self,
) -> impl DoubleEndedIterator<Item = impl DoubleEndedIterator<Item = &T>>
pub fn rows_iter_ref( &self, ) -> impl DoubleEndedIterator<Item = impl DoubleEndedIterator<Item = &T>>
Returns an iterator over all rows.
Each Item
is itself another Iterator
over references to the elements in that column.
Sourcepub fn chunks_iter_ref(
&self,
chunk_size: usize,
) -> impl DoubleEndedIterator<Item = &[T]>
pub fn chunks_iter_ref( &self, chunk_size: usize, ) -> impl DoubleEndedIterator<Item = &[T]>
Returns an iterator over chunk_len
references to elements in row major order.
§Panics
If chunk_size
is 0.
Sourcepub fn chunks_iter_ref_mut(
&mut self,
chunk_size: usize,
) -> impl DoubleEndedIterator<Item = &mut [T]>
pub fn chunks_iter_ref_mut( &mut self, chunk_size: usize, ) -> impl DoubleEndedIterator<Item = &mut [T]>
Returns an iterator over chunk_len
mutable references to elements in row major order.
§Panics
If chunk_size
is 0.
Source§impl<T: Copy, S: Storage, const SIZE: usize> Grid2D<T, S, SIZE>
§iterators (Copy)
impl<T: Copy, S: Storage, const SIZE: usize> Grid2D<T, S, SIZE>
§iterators (Copy)
Sourcepub fn iter(&self) -> impl DoubleEndedIterator<Item = T> + '_
pub fn iter(&self) -> impl DoubleEndedIterator<Item = T> + '_
Returns an iterator over copies of all elements in row major order.
Sourcepub fn row_iter(
&self,
row: usize,
) -> Result<impl DoubleEndedIterator<Item = T> + '_>
pub fn row_iter( &self, row: usize, ) -> Result<impl DoubleEndedIterator<Item = T> + '_>
Returns an iterator over references to all elements in the given row.
Sourcepub fn row_iter_unchecked(
&self,
row: usize,
) -> impl DoubleEndedIterator<Item = T> + '_
pub fn row_iter_unchecked( &self, row: usize, ) -> impl DoubleEndedIterator<Item = T> + '_
Sourcepub fn rows_iter(
&self,
) -> impl DoubleEndedIterator<Item = impl DoubleEndedIterator<Item = T> + '_>
pub fn rows_iter( &self, ) -> impl DoubleEndedIterator<Item = impl DoubleEndedIterator<Item = T> + '_>
Returns an iterator over all rows.
Each Item
is itself another Iterator
over copies of the elements in that column.
Source§impl<T, S: Storage, const SIZE: usize> Grid2D<T, S, SIZE>
§slices
impl<T, S: Storage, const SIZE: usize> Grid2D<T, S, SIZE>
§slices
Sourcepub fn as_mut_slice(&mut self) -> &mut [T]
pub fn as_mut_slice(&mut self) -> &mut [T]
Returns a mutable slice of the grid.
Sourcepub fn row_slice_unchecked(&self, row: usize) -> &[T]
pub fn row_slice_unchecked(&self, row: usize) -> &[T]
Sourcepub fn row_mut_slice(&mut self, row: usize) -> Result<&mut [T]>
pub fn row_mut_slice(&mut self, row: usize) -> Result<&mut [T]>
Returns a mutable slice of requested row
.
Sourcepub fn row_mut_slice_unchecked(&mut self, row: usize) -> &mut [T]
pub fn row_mut_slice_unchecked(&mut self, row: usize) -> &mut [T]
Source§impl<T, S: Storage, const SIZE: usize> Grid2D<T, S, SIZE>
§get chunks
impl<T, S: Storage, const SIZE: usize> Grid2D<T, S, SIZE>
§get chunks
Sourcepub fn get_chunk(
&self,
chunk_len: usize,
col: usize,
row: usize,
) -> Result<&[T]>
pub fn get_chunk( &self, chunk_len: usize, col: usize, row: usize, ) -> Result<&[T]>
Returns a slice of the chunk of elements at the given row
and col
umn.
Trait Implementations§
Source§impl<T: Default, const SIZE: usize> Default for Grid2D<T, (), SIZE>
impl<T: Default, const SIZE: usize> Default for Grid2D<T, (), SIZE>
Source§impl<T: Default, const SIZE: usize> Default for Grid2D<T, Boxed, SIZE>
Available on crate feature alloc
only.
impl<T: Default, const SIZE: usize> Default for Grid2D<T, Boxed, SIZE>
alloc
only.