Skip to main content

GridWrite

Trait GridWrite 

Source
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§

Source

type Element

The type of elements in the grid.

Source

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§

Source

fn set(&mut self, pos: Pos, value: Self::Element) -> Result<(), GridError>

Sets the element at a specified position.

§Errors

Returns an error if the position is out of bounds.

Provided Methods§

Source

fn clear(&mut self)
where Self::Element: Default, Self: ExactSizeGrid,

Clears the grid, setting all elements to their default value.

Elements are set in an order agreeable to the grid’s internal layout.

Source

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.

Source

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.

Source

fn fill_solid(&mut self, value: Self::Element)
where Self::Element: Copy, Self: ExactSizeGrid,

Sets elements within the grid to a single value.

Elements are set in an order agreeable to the grid’s internal layout.

Source

fn clear_rect(&mut self, bounds: Rect)
where Self::Element: Default,

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.).

Source

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.).

Source

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.).

Source

fn fill_rect_solid(&mut self, dst: Rect, value: Self::Element)
where Self::Element: Copy,

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.
Source§

type Element = <T as GridWrite>::Element

Source§

type Layout = <T as GridWrite>::Layout

Source§

fn set(&mut self, pos: Pos, value: Self::Element) -> Result<(), GridError>

Source§

fn fill_rect(&mut self, bounds: Rect, f: impl FnMut(Pos) -> Self::Element)

Source§

fn fill_rect_iter( &mut self, dst: Rect, iter: impl IntoIterator<Item = Self::Element>, )

Source§

fn fill_rect_solid(&mut self, dst: Rect, value: Self::Element)
where Self::Element: Copy,

Source§

impl<T> GridWrite for RefCell<T>
where T: GridWrite,

Available on crate feature cell only.
Source§

type Element = <T as GridWrite>::Element

Source§

type Layout = <T as GridWrite>::Layout

Source§

fn set(&mut self, pos: Pos, value: Self::Element) -> Result<(), GridError>

Source§

fn fill_rect(&mut self, bounds: Rect, f: impl FnMut(Pos) -> Self::Element)

Source§

fn fill_rect_iter( &mut self, dst: Rect, iter: impl IntoIterator<Item = Self::Element>, )

Source§

fn fill_rect_solid(&mut self, dst: Rect, value: Self::Element)
where Self::Element: Copy,

Source§

impl<T> GridWrite for UnsafeCell<T>
where T: GridWrite,

Available on crate feature cell only.
Source§

type Element = <T as GridWrite>::Element

Source§

type Layout = <T as GridWrite>::Layout

Source§

fn set(&mut self, pos: Pos, value: Self::Element) -> Result<(), GridError>

Source§

fn fill_rect(&mut self, bounds: Rect, f: impl FnMut(Pos) -> Self::Element)

Source§

fn fill_rect_iter( &mut self, dst: Rect, iter: impl IntoIterator<Item = Self::Element>, )

Source§

fn fill_rect_solid(&mut self, dst: Rect, value: Self::Element)
where Self::Element: Copy,

Implementors§

Source§

impl<G, F> GridWrite for Blended<'_, G, F>
where G: GridRead + GridWrite, F: Fn(<G as GridRead>::Element<'_>, <G as GridWrite>::Element) -> <G as GridWrite>::Element, <G as GridWrite>::Element: Copy,

Source§

impl<T: GridBase + GridWriteUnchecked + TrustedSizeGrid> GridWrite for T

Automatically implement GridWrite when GridWriteUnchecked + TrustedSizeGrid are implemented.