pub struct GenericGrid<T> { /* private fields */ }
Expand description
A two-dimensional grid of an arbitrary type T
Implementations§
Source§impl<T: Default + Clone> GenericGrid<T>
impl<T: Default + Clone> GenericGrid<T>
Sourcepub fn new(width: usize, height: usize) -> GenericGrid<T>
pub fn new(width: usize, height: usize) -> GenericGrid<T>
Constructs a new two-dimensional GenericGrid<T>
of size width
xheight
with default values of type T
.
Sourcepub fn get(&self, x: usize, y: usize) -> Option<&T>
pub fn get(&self, x: usize, y: usize) -> Option<&T>
Returns the element at position (x, y), or None
if the position
is out of bounds.
Sourcepub fn get_unchecked(&self, x: usize, y: usize) -> &T
pub fn get_unchecked(&self, x: usize, y: usize) -> &T
Returns a pointer to the element at position (x, y), without doing bounds checking.
Sourcepub fn set(&mut self, x: usize, y: usize, value: T)
pub fn set(&mut self, x: usize, y: usize, value: T)
Sets the value of the grid at position (x,y)
Sourcepub fn to_vec(self) -> Vec<T>
pub fn to_vec(self) -> Vec<T>
Converts the GenericGrid<T>
to a Vec<T>
with indexing
grid[x, y] == vec[y*grid.width + x]
Sourcepub fn iter(&self) -> GridIter<'_, T> ⓘ
pub fn iter(&self) -> GridIter<'_, T> ⓘ
Returns an iterator over the nodes of the grid.
An item of the iterator contains the position
and a reference to the node: (x, y, value)
Sourcepub fn iter_mut(&mut self) -> GridIterMut<'_, T> ⓘ
pub fn iter_mut(&mut self) -> GridIterMut<'_, T> ⓘ
Returns an iterator over the nodes of the grid.
An item of the iterator contains the position
and a mutable reference to the node: (x, y, value)
Trait Implementations§
Source§impl<T: Clone> Clone for GenericGrid<T>
impl<T: Clone> Clone for GenericGrid<T>
Source§fn clone(&self) -> GenericGrid<T>
fn clone(&self) -> GenericGrid<T>
Returns a copy of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreAuto Trait Implementations§
impl<T> Freeze for GenericGrid<T>
impl<T> RefUnwindSafe for GenericGrid<T>where
T: RefUnwindSafe,
impl<T> Send for GenericGrid<T>where
T: Send,
impl<T> Sync for GenericGrid<T>where
T: Sync,
impl<T> Unpin for GenericGrid<T>where
T: Unpin,
impl<T> UnwindSafe for GenericGrid<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more