[−][src]Trait gridly::prelude::Grid
Base Reader trait for grids.
This trait provides the grid's cell type, Item
, and a single, unsafe
reader function, get_unchecked
, which provides a reference to a cell at a
location.
The Grid
trait, which is automatically implemented for all [BaseGrid
],
provides a safe and comprehensive interface to a BaseGrid
, which includes
bounds checking based on GridBounds
and many different view and iterator
methods.
Trait for viewing the values in a grid
Grid
provides a comprehensive interface for reading values in a grid. This
interface includes bounds-checked getters, iterators, and views.
Associated Types
type Item
The item type stored in the grid
Required methods
unsafe fn get_unchecked(&self, location: &Location) -> &Self::Item
Get a reference to a cell, without doing bounds checking. Implementors
of this method are allowed to assume that bounds checking has already
been performed on the location, which means that implementors are allowed
to do their own unsafe get
operations on the underlying storage,
where relevant / possible.
Provided methods
fn get(&self, location: impl LocationLike) -> Result<&Self::Item, BoundsError>
Get a reference to a cell in a grid. Returns an error if the location is out of bounds with the specific boundary violation.
fn view<T: LocComponent>(&self) -> View<Self, T>
fn rows(&self) -> RowsView<Self>
Get a view of a grid's rows. See [View]
for details.
fn columns(&self) -> ColumnsView<Self>
Get a view of a grid's columns. See [View]
for details.
unsafe fn single_view_unchecked<T: LocComponent>(
&self,
index: T
) -> SingleView<Self, T>
&self,
index: T
) -> SingleView<Self, T>
Get a view of a single row or column in a grid, without bounds checking that row or column index.
unsafe fn row_unchecked(&self, row: Row) -> RowView<Self>
Get a view of a single row in a grid, without bounds checking that row's index. Because
this method is unsafe, we require the type safety of a Row (rather than Into
unsafe fn column_unchecked(&self, column: Column) -> ColumnView<Self>
Get a view of a single column in a grid, without bounds checking that column's index.
Because this method is unsafe, we require the type safety of a Column (rather than
Into
fn single_view<T: LocComponent>(
&self,
index: T
) -> Result<SingleView<Self, T>, RangeError<T>>
&self,
index: T
) -> Result<SingleView<Self, T>, RangeError<T>>
Get a view of a single row or column in a grid. Returns an error if the index of the row or column is out of bounds for the grid.
fn row(&self, row: impl Into<Row>) -> Result<RowView<Self>, RowRangeError>
Get a view of a single row in a grid. Returns an error if the index of the row is out of bounds for the grid.
fn column(
&self,
column: impl Into<Column>
) -> Result<ColumnView<Self>, ColumnRangeError>
&self,
column: impl Into<Column>
) -> Result<ColumnView<Self>, ColumnRangeError>
Get a view of a single column in a grid. Returns an error if the index of the column is out of bounds for the grid.