pub struct Grid<T> { /* private fields */ }Expand description
A data structure for storing a 2d sized grid of data.
Implementations§
Source§impl<T> Grid<T>
impl<T> Grid<T>
pub fn new(size: impl GridPoint) -> Self
Sourcepub fn filled(value: T, size: impl GridPoint) -> Selfwhere
T: Clone,
pub fn filled(value: T, size: impl GridPoint) -> Selfwhere
T: Clone,
Creates a new Grid with all elements set to the given default value.
Sourcepub fn insert_row(&mut self, y: usize, row: impl DoubleEndedIterator<Item = T>)
pub fn insert_row(&mut self, y: usize, row: impl DoubleEndedIterator<Item = T>)
Insert into a row of the grid using an iterator.
Will insert up to the length of a row.
Sourcepub fn insert_row_at(
&mut self,
xy: impl GridPoint,
row: impl Iterator<Item = T>,
)
pub fn insert_row_at( &mut self, xy: impl GridPoint, row: impl Iterator<Item = T>, )
Insert into a row of the grid using an iterator.
Will insert up to the length of a row.
Sourcepub fn insert_column(&mut self, x: usize, column: impl IntoIterator<Item = T>)
pub fn insert_column(&mut self, x: usize, column: impl IntoIterator<Item = T>)
Insert into a column of the grid using an iterator.
Will insert up to the height of a column.
Sourcepub fn insert_column_at(
&mut self,
xy: impl GridPoint,
column: impl IntoIterator<Item = T>,
)
pub fn insert_column_at( &mut self, xy: impl GridPoint, column: impl IntoIterator<Item = T>, )
Insert into a column of the grid using an iterator.
Will insert up to the height of a column.
Sourcepub fn get(&self, xy: impl GridPoint) -> Option<&T>
pub fn get(&self, xy: impl GridPoint) -> Option<&T>
Try to retrieve the value at the given position.
Returns None if the position is out of bounds.
Sourcepub fn get_mut(&mut self, xy: impl GridPoint) -> Option<&mut T>
pub fn get_mut(&mut self, xy: impl GridPoint) -> Option<&mut T>
Try to retrieve the mutable value at the given position.
Returns None if the position is out of bounds.
Sourcepub fn iter(&self) -> impl DoubleEndedIterator<Item = &T>
pub fn iter(&self) -> impl DoubleEndedIterator<Item = &T>
An iterator over all elements in the grid.
Sourcepub fn iter_mut(&mut self) -> impl DoubleEndedIterator<Item = &mut T>
pub fn iter_mut(&mut self) -> impl DoubleEndedIterator<Item = &mut T>
A mutable iterator over all elements in the grid.
Sourcepub fn iter_row(&self, y: usize) -> impl DoubleEndedIterator<Item = &T>
pub fn iter_row(&self, y: usize) -> impl DoubleEndedIterator<Item = &T>
An iterator over a single row of the grid.
Goes from left to right.
Sourcepub fn iter_row_mut(
&mut self,
y: usize,
) -> impl DoubleEndedIterator<Item = &mut T>
pub fn iter_row_mut( &mut self, y: usize, ) -> impl DoubleEndedIterator<Item = &mut T>
A mutable iterator over a single row of the grid.
Iterates from left to right.
Sourcepub fn iter_column(&self, x: usize) -> impl DoubleEndedIterator<Item = &T>
pub fn iter_column(&self, x: usize) -> impl DoubleEndedIterator<Item = &T>
An iterator over a single column of the grid.
Goes from bottom to top.
Sourcepub fn iter_column_mut(
&mut self,
x: usize,
) -> impl DoubleEndedIterator<Item = &mut T>
pub fn iter_column_mut( &mut self, x: usize, ) -> impl DoubleEndedIterator<Item = &mut T>
A mutable iterator over a single column of the grid.
Goes from bottom to top.
Sourcepub fn iter_xy(&self) -> impl Iterator<Item = (IVec2, &T)>
pub fn iter_xy(&self) -> impl Iterator<Item = (IVec2, &T)>
Iterate over all grid elements along with their 2d positions.
Sourcepub fn iter_xy_mut(&mut self) -> impl Iterator<Item = (IVec2, &mut T)>
pub fn iter_xy_mut(&mut self) -> impl Iterator<Item = (IVec2, &mut T)>
Iterate over all grid elements along with their 2d positions.
Sourcepub fn iter_rect(&self, rect: GridRect) -> impl Iterator<Item = (IVec2, &T)>
pub fn iter_rect(&self, rect: GridRect) -> impl Iterator<Item = (IVec2, &T)>
Iterate over a rectangular section of grid elements along with their 2d positions.