pub trait GridWrite: GridBase {
type Element;
type Layout: Layout;
// Required method
fn set(&mut self, pos: Pos, value: Self::Element) -> Result<(), GridError>;
// Provided methods
fn clear(&mut self)
where Self::Element: Default,
Self: ExactSizeGrid { ... }
fn fill(&mut self, f: impl FnMut(Pos) -> Self::Element)
where Self: ExactSizeGrid { ... }
fn fill_iter(&mut self, iter: impl Iterator<Item = Self::Element>)
where Self: ExactSizeGrid { ... }
fn fill_solid(&mut self, value: Self::Element)
where Self::Element: Copy,
Self: ExactSizeGrid { ... }
fn clear_rect(&mut self, bounds: Rect)
where Self::Element: Default { ... }
fn fill_rect(&mut self, bounds: Rect, f: impl FnMut(Pos) -> Self::Element) { ... }
fn fill_rect_iter(
&mut self,
dst: Rect,
iter: impl IntoIterator<Item = Self::Element>,
) { ... }
fn fill_rect_solid(&mut self, dst: Rect, value: Self::Element)
where Self::Element: Copy { ... }
}Expand description
Write elements to a 2-dimensional grid position.
Required Associated Types§
Sourcetype Layout: Layout
type Layout: Layout
The type of layout used for the grid.
§Implementation
It is not guaranteed that the internal storage of the grid matches this layout, but methods that return iterators over the grid’s elements or positions should return them in the traversal order defined by this layout.
RowMajor is a reasonable default implementation for most grids.
Required Methods§
Provided Methods§
Sourcefn clear(&mut self)
fn clear(&mut self)
Clears the grid, setting all elements to their default value.
Elements are set in an order agreeable to the grid’s internal layout.
Sourcefn fill(&mut self, f: impl FnMut(Pos) -> Self::Element)where
Self: ExactSizeGrid,
fn fill(&mut self, f: impl FnMut(Pos) -> Self::Element)where
Self: ExactSizeGrid,
Sets elements within the grid.
Elements are set in an order agreeable to the grid’s internal layout.
Sourcefn fill_iter(&mut self, iter: impl Iterator<Item = Self::Element>)where
Self: ExactSizeGrid,
fn fill_iter(&mut self, iter: impl Iterator<Item = Self::Element>)where
Self: ExactSizeGrid,
Sets elements within the grid from an iterator.
Elements are set in an order agreeable to the grid’s internal layout.
Sourcefn fill_solid(&mut self, value: Self::Element)
fn fill_solid(&mut self, value: Self::Element)
Sets elements within the grid to a single value.
Elements are set in an order agreeable to the grid’s internal layout.
Sourcefn clear_rect(&mut self, bounds: Rect)
fn clear_rect(&mut self, bounds: Rect)
Clears a rectangular region of the grid, setting all elements to their default value.
Elements are set in an order agreeable to the grid’s internal layout. Out-of-bounds elements are skipped, and the bounding rectangle is treated as exclusive of the right and bottom edges.
§Performance
The default implementation uses Layout::iter_pos to iterate over the rectangle,
involving bounds checking for each element. Other implementations may optimize this, for
example by using a more efficient iteration strategy (for linear reads, reduced bounds
checking, etc.).
Sourcefn fill_rect(&mut self, bounds: Rect, f: impl FnMut(Pos) -> Self::Element)
fn fill_rect(&mut self, bounds: Rect, f: impl FnMut(Pos) -> Self::Element)
Sets elements within a rectangular region of the grid.
Elements are set in an order agreeable to the grid’s internal layout. Out-of-bounds elements are skipped, and the bounding rectangle is treated as exclusive of the right and bottom edges.
§Performance
The default implementation uses Layout::iter_pos to iterate over the rectangle,
involving bounds checking for each element. Other implementations may optimize this, for
example by using a more efficient iteration strategy (for linear reads, reduced bounds
checking, etc.).
Sourcefn fill_rect_iter(
&mut self,
dst: Rect,
iter: impl IntoIterator<Item = Self::Element>,
)
fn fill_rect_iter( &mut self, dst: Rect, iter: impl IntoIterator<Item = Self::Element>, )
Sets elements within a rectangular region of the grid.
Elements are set in an order agreeable to the grid’s internal layout. Out-of-bounds elements are skipped, and the bounding rectangle is treated as exclusive of the right and bottom edges.
If the provided iterator has fewer elements than the rectangle, the remaining elements will not be set.
§Performance
The default implementation uses Layout::iter_pos to iterate over the rectangle,
involving bounds checking for each element. Other implementations may optimize this, for
example by using a more efficient iteration strategy (for linear reads, reduced bounds
checking, etc.).
Sourcefn fill_rect_solid(&mut self, dst: Rect, value: Self::Element)
fn fill_rect_solid(&mut self, dst: Rect, value: Self::Element)
Sets elements within a rectangular region of the grid.
Elements are set in an order agreeable to the grid’s internal layout. Out-of-bounds elements are skipped, and the bounding rectangle is treated as exclusive of the right and bottom edges.
§Performance
The default implementation uses Layout::iter_pos to iterate over the rectangle,
involving bounds checking for each element. Other implementations may optimize this, for
example by using a more efficient iteration strategy (for linear reads, reduced bounds
checking, etc.).
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementations on Foreign Types§
Source§impl<T> GridWrite for Cell<T>where
T: GridWrite,
Available on crate feature cell only.
impl<T> GridWrite for Cell<T>where
T: GridWrite,
cell only.type Element = <T as GridWrite>::Element
type Layout = <T as GridWrite>::Layout
fn set(&mut self, pos: Pos, value: Self::Element) -> Result<(), GridError>
fn fill_rect(&mut self, bounds: Rect, f: impl FnMut(Pos) -> Self::Element)
fn fill_rect_iter( &mut self, dst: Rect, iter: impl IntoIterator<Item = Self::Element>, )
fn fill_rect_solid(&mut self, dst: Rect, value: Self::Element)
Source§impl<T> GridWrite for RefCell<T>where
T: GridWrite,
Available on crate feature cell only.
impl<T> GridWrite for RefCell<T>where
T: GridWrite,
cell only.type Element = <T as GridWrite>::Element
type Layout = <T as GridWrite>::Layout
fn set(&mut self, pos: Pos, value: Self::Element) -> Result<(), GridError>
fn fill_rect(&mut self, bounds: Rect, f: impl FnMut(Pos) -> Self::Element)
fn fill_rect_iter( &mut self, dst: Rect, iter: impl IntoIterator<Item = Self::Element>, )
fn fill_rect_solid(&mut self, dst: Rect, value: Self::Element)
Source§impl<T> GridWrite for UnsafeCell<T>where
T: GridWrite,
Available on crate feature cell only.
impl<T> GridWrite for UnsafeCell<T>where
T: GridWrite,
cell only.type Element = <T as GridWrite>::Element
type Layout = <T as GridWrite>::Layout
fn set(&mut self, pos: Pos, value: Self::Element) -> Result<(), GridError>
fn fill_rect(&mut self, bounds: Rect, f: impl FnMut(Pos) -> Self::Element)
fn fill_rect_iter( &mut self, dst: Rect, iter: impl IntoIterator<Item = Self::Element>, )
fn fill_rect_solid(&mut self, dst: Rect, value: Self::Element)
Implementors§
Source§impl<T: GridBase + GridWriteUnchecked + TrustedSizeGrid> GridWrite for T
Automatically implement GridWrite when GridWriteUnchecked + TrustedSizeGrid are implemented.
impl<T: GridBase + GridWriteUnchecked + TrustedSizeGrid> GridWrite for T
Automatically implement GridWrite when GridWriteUnchecked + TrustedSizeGrid are implemented.