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 Qa
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 Qa 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, qa: impl Borrow<Qa<W, H>>) -> &T
pub fn get(&self, qa: impl Borrow<Qa<W, H>>) -> &T
Get a reference to an element of the grid.
We use get_unchecked internally, because we guarantee the validity of the Qa index on construction.
sourcepub fn get_mut(&mut self, qa: impl Borrow<Qa<W, H>>) -> &mut T
pub fn get_mut(&mut self, qa: impl Borrow<Qa<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 Qa 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 (Qa<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 (Qa<W, H>, T)> for Grid<T, W, H, SIZE>
source§fn extend<I>(&mut self, iter: I)where
I: IntoIterator<Item = &'a (Qa<W, H>, T)>,
fn extend<I>(&mut self, iter: I)where
I: IntoIterator<Item = &'a (Qa<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<(Qa<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<(Qa<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<(Qa<W, H>, T)> for Grid<T, W, H, SIZE>
impl<T, const W: u16, const H: u16, const SIZE: usize> Extend<(Qa<W, H>, T)> for Grid<T, W, H, SIZE>
source§fn extend<I>(&mut self, iter: I)where
I: IntoIterator<Item = (Qa<W, H>, T)>,
fn extend<I>(&mut self, iter: I)where
I: IntoIterator<Item = (Qa<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.