Struct tapestry::grid::Grid [−][src]
The core type of this library. A 2D grid of cell type T
.
Fields
cells: Vec<T>
Row-major, linear storage of cell data.
bounds: Rect
Implementations
impl<T> Grid<T>
[src]
pub fn new(bounds: Rect) -> Self where
T: Default + Clone,
[src]
T: Default + Clone,
pub fn with_generator<C>(bounds: Rect, generator: impl Fn(C) -> T) -> Self where
C: From<Coord>,
[src]
C: From<Coord>,
pub fn get<C: Into<Coord>>(&self, coord: C) -> Option<&T>
[src]
pub fn get_mut<C: Into<Coord>>(&mut self, coord: C) -> Option<&mut T>
[src]
pub fn set<C: Into<Coord>>(&mut self, coord: C, value: T) -> bool
[src]
pub fn replace<C: Into<Coord>>(&mut self, coord: C, value: T) -> Option<T>
[src]
pub fn take<C: Into<Coord>>(&mut self, coord: C) -> Option<T> where
T: Default,
[src]
T: Default,
pub fn copy<C1, C2>(&mut self, src: C1, dest: C2) -> bool where
T: Copy,
C1: Into<Coord>,
C2: Into<Coord>,
[src]
T: Copy,
C1: Into<Coord>,
C2: Into<Coord>,
pub fn swap<C1, C2>(&mut self, coord1: C1, coord2: C2) -> bool where
C1: Into<Coord>,
C2: Into<Coord>,
[src]
C1: Into<Coord>,
C2: Into<Coord>,
Swaps the contents of two cells.
pub fn mov(&mut self, src: Coord, dest: Coord) -> Option<T> where
T: Default,
[src]
T: Default,
Moves the contents of src
into dest
, returning the previous contents
of dest
.
pub fn iter<'a>(&'a self) -> impl Iterator<Item = (Coord, &'a T)>
[src]
Returns an iterator over all cells in the grid.
pub fn cell_iter_mut(&mut self) -> impl Iterator<Item = &mut T>
[src]
pub fn selection_iter<I>(&self, coords: I) -> SelectionIter<'_, T, I>ⓘ where
I: Iterator<Item = Coord>,
[src]
I: Iterator<Item = Coord>,
Returns an iterator over the cells specified by the coords iterator.
pub fn selection_iter_mut<I>(&mut self, coords: I) -> SelectionIterMut<'_, T, I>ⓘ where
I: Iterator<Item = Coord>,
[src]
I: Iterator<Item = Coord>,
Returns a mutable iterator over the cells specified by the coords iterator.
If there is an attempt to visit a given cell more than once (which would
create multiple simultaneous mutable references to the cell), a
GridError::AlreadyVisited
will be returned
in place of the cell contents.
pub fn flood_iter<C: Into<Coord>>(
&self,
starting_coord: C,
predicate: impl Fn(&T) -> bool + 'static
) -> FloodIter<'_, T>ⓘ
[src]
&self,
starting_coord: C,
predicate: impl Fn(&T) -> bool + 'static
) -> FloodIter<'_, T>ⓘ
Returns an iterator beginning from starting_coord
and continuing
through all recursively adjacent coords that satisfy the predicate
. In
other words, this iterates through the cells according to a flood fill
algorithm.
Since there is no mut
version of this iterator (which would require
simultaneous mutable and shared references to most of the cells), the
resulting iterator can be collected and then passed into
Grid::selection_iter_mut
to
gain access to mutable cell contents.
Trait Implementations
Auto Trait Implementations
impl<T> RefUnwindSafe for Grid<T> where
T: RefUnwindSafe,
T: RefUnwindSafe,
impl<T> Send for Grid<T> where
T: Send,
T: Send,
impl<T> Sync for Grid<T> where
T: Sync,
T: Sync,
impl<T> Unpin for Grid<T> where
T: Unpin,
T: Unpin,
impl<T> UnwindSafe for Grid<T> where
T: UnwindSafe,
T: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,