Struct tapestry::grid::Grid[][src]

pub struct Grid<T> {
    pub cells: Vec<T>,
    pub bounds: Rect,
}

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]

pub fn with_generator<C>(bounds: Rect, generator: impl Fn(C) -> T) -> Self where
    C: From<Coord>, 
[src]

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]

pub fn copy<C1, C2>(&mut self, src: C1, dest: C2) -> bool where
    T: Copy,
    C1: Into<Coord>,
    C2: Into<Coord>, 
[src]

pub fn swap<C1, C2>(&mut self, coord1: C1, coord2: C2) -> bool where
    C1: Into<Coord>,
    C2: Into<Coord>, 
[src]

Swaps the contents of two cells.

pub fn mov(&mut self, src: Coord, dest: Coord) -> Option<T> where
    T: Default
[src]

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>

Notable traits for SelectionIter<'a, T, I>

impl<'a, T, I> Iterator for SelectionIter<'a, T, I> where
    I: Iterator<Item = Coord>, 
type Item = Result<(Coord, &'a T), GridError>;
where
    I: Iterator<Item = Coord>, 
[src]

Returns an iterator over the cells specified by the coords iterator.

pub fn selection_iter_mut<I>(&mut self, coords: I) -> SelectionIterMut<'_, T, I>

Notable traits for SelectionIterMut<'a, T, I>

impl<'a, T, I> Iterator for SelectionIterMut<'a, T, I> where
    I: Iterator<Item = Coord>, 
type Item = Result<(Coord, &'a mut T), GridError>;
where
    I: Iterator<Item = Coord>, 
[src]

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>

Notable traits for FloodIter<'a, T>

impl<'a, T> Iterator for FloodIter<'a, T> type Item = (Coord, &'a T);
[src]

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

impl<T> Display for Grid<T> where
    char: From<T>,
    T: Copy
[src]

Auto Trait Implementations

impl<T> RefUnwindSafe for Grid<T> where
    T: RefUnwindSafe

impl<T> Send for Grid<T> where
    T: Send

impl<T> Sync for Grid<T> where
    T: Sync

impl<T> Unpin for Grid<T> where
    T: Unpin

impl<T> UnwindSafe for Grid<T> where
    T: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,