pub trait GridSetter: Grid {
    // Required methods
    unsafe fn replace_unchecked(
        &mut self,
        location: Location,
        value: Self::Item
    ) -> Self::Item;
    unsafe fn set_unchecked(&mut self, location: Location, value: Self::Item);

    // Provided methods
    fn replace(
        &mut self,
        location: impl LocationLike,
        value: Self::Item
    ) -> Result<Self::Item, BoundsError> { ... }
    fn set(
        &mut self,
        location: impl LocationLike,
        value: Self::Item
    ) -> Result<(), BoundsError> { ... }
}
Expand description

Setter trait for grids. Allows setting and replacing elements in the grid. Implementors should implement the unsafe setter and replacer methods. This trait then provides implementations of safe, bounds-checked setters.

Required Methods§

source

unsafe fn replace_unchecked( &mut self, location: Location, value: Self::Item ) -> Self::Item

Replace the value at the given location with value, without bounds checking location. Returns the previous value in the grid.

Implementors of this method are allowed to skip bounds checking location. The safe interface to GridSetter bounds checks its arguments where necessary before calling this method.

Safety

Callers must ensure that the location has been bounds-checked before calling this method. The safe interface to Grid automatically performs this checking for you.

source

unsafe fn set_unchecked(&mut self, location: Location, value: Self::Item)

Replace the value at the given location with value, without bounds checking location.

Implementors of this method are allowed to skip bounds checking location. The safe interface to GridSetter bounds checks its arguments where necessary before calling this method.

Safety

Callers must ensure that the location has been bounds-checked before calling this method. The safe interface to Grid automatically performs this checking for you.

Provided Methods§

source

fn replace( &mut self, location: impl LocationLike, value: Self::Item ) -> Result<Self::Item, BoundsError>

Replace the value at the given location with value. Returns the previous value in the grid, or an error if the location was out of bounds.

source

fn set( &mut self, location: impl LocationLike, value: Self::Item ) -> Result<(), BoundsError>

Set the value at the given location in the grid. Returns an error if the location was out of bounds.

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl<G: GridSetter> GridSetter for &mut G

source§

unsafe fn replace_unchecked( &mut self, location: Location, value: Self::Item ) -> Self::Item

source§

unsafe fn set_unchecked(&mut self, location: Location, value: Self::Item)

source§

fn replace( &mut self, location: impl LocationLike, value: Self::Item ) -> Result<Self::Item, BoundsError>

source§

fn set( &mut self, location: impl LocationLike, value: Self::Item ) -> Result<(), BoundsError>

Implementors§