pub struct Grid<T, const WIDTH: u16, const HEIGHT: u16, const SIZE: usize>(/* private fields */);
Expand description
A grid is a generic array that can be indexed by a Pos
We can also interact with specific lines with Grid::line
and
Grid::line_mut
, or with the whole underlying array with
as_ref
and
as_mut
.
At the moment we have to provide a SIZE
argument = WIDTH
*
HEIGHT
. This value is checked at compile time, but can’t be
ellided at the moment, due to rust const generics limitations.
We can use the grid_create
macro to use a Pos
as a source
of these values.
Implementations§
source§impl<T, const W: u16, const H: u16, const SIZE: usize> Grid<T, W, H, SIZE>
impl<T, const W: u16, const H: u16, const SIZE: usize> Grid<T, W, H, SIZE>
sourcepub fn repeat(item: T) -> Selfwhere
T: Copy,
pub fn repeat(item: T) -> Selfwhere
T: Copy,
Create a grid filled with copies of the provided item
This is the fastest of the repeat_* functions, that’s why it’s the “default”.
sourcepub fn into_inner(self) -> [T; SIZE]
pub fn into_inner(self) -> [T; SIZE]
“Dismantle” a Grid into the inner array; consumes self.
sourcepub fn as_array_mut(&mut self) -> &mut [T; SIZE]
pub fn as_array_mut(&mut self) -> &mut [T; SIZE]
Return a mut reference to the inner array
sourcepub fn line_mut(&mut self, lineno: u16) -> &mut [T]
pub fn line_mut(&mut self, lineno: u16) -> &mut [T]
Return a specific grid line as a mut reference to a slice
Allows quick assignment operations on whole lines.
sourcepub fn get(&self, pos: impl Borrow<Pos<W, H>>) -> &T
pub fn get(&self, pos: impl Borrow<Pos<W, H>>) -> &T
Get a reference to an element of the grid.
We use get_unchecked internally, because we guarantee the validity of the Pos index on construction.
sourcepub fn get_mut(&mut self, pos: impl Borrow<Pos<W, H>>) -> &mut T
pub fn get_mut(&mut self, pos: impl Borrow<Pos<W, H>>) -> &mut T
Get a mut reference to an element of the grid.
We use get_unchecked internally, because we guarantee the validity of the Pos index on construction.
sourcepub fn iter_mut(&mut self) -> IterMut<'_, T>
pub fn iter_mut(&mut self) -> IterMut<'_, T>
Returns an iterator that allows modifying each value
Trait Implementations§
source§impl<T, const W: u16, const H: u16, const SIZE: usize> AsMut<[T; SIZE]> for Grid<T, W, H, SIZE>
impl<T, const W: u16, const H: u16, const SIZE: usize> AsMut<[T; SIZE]> for Grid<T, W, H, SIZE>
source§impl<T, const W: u16, const H: u16, const SIZE: usize> AsRef<[T; SIZE]> for Grid<T, W, H, SIZE>
impl<T, const W: u16, const H: u16, const SIZE: usize> AsRef<[T; SIZE]> for Grid<T, W, H, SIZE>
source§impl<T: Clone, const WIDTH: u16, const HEIGHT: u16, const SIZE: usize> Clone for Grid<T, WIDTH, HEIGHT, SIZE>
impl<T: Clone, const WIDTH: u16, const HEIGHT: u16, const SIZE: usize> Clone for Grid<T, WIDTH, HEIGHT, SIZE>
source§impl<T: Debug, const WIDTH: u16, const HEIGHT: u16, const SIZE: usize> Debug for Grid<T, WIDTH, HEIGHT, SIZE>
impl<T: Debug, const WIDTH: u16, const HEIGHT: u16, const SIZE: usize> Debug for Grid<T, WIDTH, HEIGHT, SIZE>
source§impl<T: Default, const W: u16, const H: u16, const SIZE: usize> Default for Grid<T, W, H, SIZE>
impl<T: Default, const W: u16, const H: u16, const SIZE: usize> Default for Grid<T, W, H, SIZE>
source§impl<T: Display, const W: u16, const H: u16, const SIZE: usize> Display for Grid<T, W, H, SIZE>
impl<T: Display, const W: u16, const H: u16, const SIZE: usize> Display for Grid<T, W, H, SIZE>
source§impl<'a, T: 'a + Copy, const W: u16, const H: u16, const SIZE: usize> Extend<&'a (Pos<W, H>, T)> for Grid<T, W, H, SIZE>
impl<'a, T: 'a + Copy, const W: u16, const H: u16, const SIZE: usize> Extend<&'a (Pos<W, H>, T)> for Grid<T, W, H, SIZE>
source§fn extend<I>(&mut self, iter: I)where
I: IntoIterator<Item = &'a (Pos<W, H>, T)>,
fn extend<I>(&mut self, iter: I)where
I: IntoIterator<Item = &'a (Pos<W, H>, T)>,
source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)source§impl<'a, T: 'a + Copy, const W: u16, const H: u16, const SIZE: usize> Extend<(Pos<W, H>, &'a T)> for Grid<T, W, H, SIZE>
impl<'a, T: 'a + Copy, const W: u16, const H: u16, const SIZE: usize> Extend<(Pos<W, H>, &'a T)> for Grid<T, W, H, SIZE>
source§fn extend<I>(&mut self, iter: I)
fn extend<I>(&mut self, iter: I)
source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)source§impl<T, const W: u16, const H: u16, const SIZE: usize> Extend<(Pos<W, H>, T)> for Grid<T, W, H, SIZE>
impl<T, const W: u16, const H: u16, const SIZE: usize> Extend<(Pos<W, H>, T)> for Grid<T, W, H, SIZE>
source§fn extend<I>(&mut self, iter: I)where
I: IntoIterator<Item = (Pos<W, H>, T)>,
fn extend<I>(&mut self, iter: I)where
I: IntoIterator<Item = (Pos<W, H>, T)>,
source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)source§impl<'a, T: 'a + Copy + Default, const W: u16, const H: u16, const SIZE: usize> FromIterator<&'a T> for Grid<T, W, H, SIZE>
impl<'a, T: 'a + Copy + Default, const W: u16, const H: u16, const SIZE: usize> FromIterator<&'a T> for Grid<T, W, H, SIZE>
Creates a Grid from an iterator that returns references
Assumes we are getting exactly all grid elements; it panics otherwise.
source§impl<T: Default, const W: u16, const H: u16, const SIZE: usize> FromIterator<T> for Grid<T, W, H, SIZE>
impl<T: Default, const W: u16, const H: u16, const SIZE: usize> FromIterator<T> for Grid<T, W, H, SIZE>
Creates a Grid from an iterator that returns values
Assumes we are getting exactly all grid elements; it panics otherwise.
source§fn from_iter<I>(iter: I) -> Selfwhere
I: IntoIterator<Item = T>,
fn from_iter<I>(iter: I) -> Selfwhere
I: IntoIterator<Item = T>,
source§impl<T: Hash, const WIDTH: u16, const HEIGHT: u16, const SIZE: usize> Hash for Grid<T, WIDTH, HEIGHT, SIZE>
impl<T: Hash, const WIDTH: u16, const HEIGHT: u16, const SIZE: usize> Hash for Grid<T, WIDTH, HEIGHT, SIZE>
source§impl<T, APOS, const W: u16, const H: u16, const SIZE: usize> Index<APOS> for Grid<T, W, H, SIZE>
impl<T, APOS, const W: u16, const H: u16, const SIZE: usize> Index<APOS> for Grid<T, W, H, SIZE>
source§impl<T, APOS, const W: u16, const H: u16, const SIZE: usize> IndexMut<APOS> for Grid<T, W, H, SIZE>
impl<T, APOS, const W: u16, const H: u16, const SIZE: usize> IndexMut<APOS> for Grid<T, W, H, SIZE>
source§impl<'a, T, const W: u16, const H: u16, const SIZE: usize> IntoIterator for &'a Grid<T, W, H, SIZE>
impl<'a, T, const W: u16, const H: u16, const SIZE: usize> IntoIterator for &'a Grid<T, W, H, SIZE>
source§impl<'a, T, const W: u16, const H: u16, const SIZE: usize> IntoIterator for &'a mut Grid<T, W, H, SIZE>
impl<'a, T, const W: u16, const H: u16, const SIZE: usize> IntoIterator for &'a mut Grid<T, W, H, SIZE>
source§impl<Item, const W: u16, const H: u16, const WORDS: usize, const SIZE: usize> MapPos<Item, W, H, WORDS, SIZE> for Grid<Item, W, H, SIZE>where
Item: Copy,
impl<Item, const W: u16, const H: u16, const WORDS: usize, const SIZE: usize> MapPos<Item, W, H, WORDS, SIZE> for Grid<Item, W, H, SIZE>where
Item: Copy,
source§impl<T: Ord, const WIDTH: u16, const HEIGHT: u16, const SIZE: usize> Ord for Grid<T, WIDTH, HEIGHT, SIZE>
impl<T: Ord, const WIDTH: u16, const HEIGHT: u16, const SIZE: usize> Ord for Grid<T, WIDTH, HEIGHT, SIZE>
1.21.0 · source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
source§impl<T: PartialEq, const WIDTH: u16, const HEIGHT: u16, const SIZE: usize> PartialEq for Grid<T, WIDTH, HEIGHT, SIZE>
impl<T: PartialEq, const WIDTH: u16, const HEIGHT: u16, const SIZE: usize> PartialEq for Grid<T, WIDTH, HEIGHT, SIZE>
source§impl<T: PartialOrd, const WIDTH: u16, const HEIGHT: u16, const SIZE: usize> PartialOrd for Grid<T, WIDTH, HEIGHT, SIZE>
impl<T: PartialOrd, const WIDTH: u16, const HEIGHT: u16, const SIZE: usize> PartialOrd for Grid<T, WIDTH, HEIGHT, SIZE>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read more