pub struct ZeroRoot<G> { /* private fields */ }
Expand description
Grid adapter that translates the locations of the wrapped grid such that
the root is always (0, 0)
. Useful when combined with Window
.
§Example
use gridly_grids::SparseGrid;
use gridly_adapters::ZeroRoot;
use gridly::prelude::*;
let mut grid: SparseGrid<i32> = SparseGrid::new_rooted(Row(1) + Column(1), Rows(3) + Columns(4));
grid.set(Row(1) + Column(2), 4).unwrap();
grid.set(Row(2) + Column(3), 5).unwrap();
let grid = ZeroRoot::new(grid);
assert_eq!(grid.get((0, 0)).ok(), Some(&0));
assert_eq!(grid.get((0, 1)).ok(), Some(&4));
assert_eq!(grid.get((1, 1)).ok(), Some(&0));
assert_eq!(grid.get((1, 2)).ok(), Some(&5));
assert_eq!(grid.get((3, 4)).ok(), None);
Implementations§
Source§impl<G> ZeroRoot<G>
impl<G> ZeroRoot<G>
pub fn into_inner(self) -> G
Trait Implementations§
Source§impl<G: Grid> Grid for ZeroRoot<G>
impl<G: Grid> Grid for ZeroRoot<G>
Source§unsafe fn get_unchecked(&self, location: Location) -> &Self::Item
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. Read moreSource§fn get(&self, location: impl LocationLike) -> Result<&Self::Item, BoundsError>
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.
Source§fn view<T>(&self) -> View<'_, Self, T>where
T: Component,
fn view<T>(&self) -> View<'_, Self, T>where
T: Component,
Get a view of a grid, over its rows or columns. A view of a grid is
similar to a slice, but instead of being a view over specific elements,
it’s a view over the rows and columns. See
[View]
for details.Source§fn columns(&self) -> View<'_, Self, Column>
fn columns(&self) -> View<'_, Self, Column>
Get a view of a grid’s columns. See
[View]
for details.Source§unsafe fn single_view_unchecked<T>(&self, index: T) -> SingleView<'_, Self, T>where
T: Component,
unsafe fn single_view_unchecked<T>(&self, index: T) -> SingleView<'_, Self, T>where
T: Component,
Get a view of a single row or column in a grid, without bounds
checking that row or column index. Read more
Source§unsafe fn row_unchecked(&self, row: Row) -> SingleView<'_, Self, Row>
unsafe fn row_unchecked(&self, row: Row) -> SingleView<'_, Self, Row>
Get a view of a single row in a grid, without bounds checking that row’s index. Read more
Source§unsafe fn column_unchecked(
&self,
column: Column,
) -> SingleView<'_, Self, Column>
unsafe fn column_unchecked( &self, column: Column, ) -> SingleView<'_, Self, Column>
Get a view of a single column in a grid, without bounds checking that column’s index. Read more
Source§fn single_view<T>(
&self,
index: T,
) -> Result<SingleView<'_, Self, T>, RangeError<T>>where
T: Component,
fn single_view<T>(
&self,
index: T,
) -> Result<SingleView<'_, Self, T>, RangeError<T>>where
T: Component,
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.
Source§fn row(
&self,
row: impl Into<Row>,
) -> Result<SingleView<'_, Self, Row>, RangeError<Row>>
fn row( &self, row: impl Into<Row>, ) -> Result<SingleView<'_, Self, Row>, RangeError<Row>>
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.
Source§fn column(
&self,
column: impl Into<Column>,
) -> Result<SingleView<'_, Self, Column>, RangeError<Column>>
fn column( &self, column: impl Into<Column>, ) -> Result<SingleView<'_, Self, Column>, RangeError<Column>>
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.
Source§fn display_with<T, F>(&self, func: F) -> DisplayAdapter<&Self, F>
fn display_with<T, F>(&self, func: F) -> DisplayAdapter<&Self, F>
Source§impl<G: GridBounds> GridBounds for ZeroRoot<G>
impl<G: GridBounds> GridBounds for ZeroRoot<G>
Source§fn dimensions(&self) -> Vector
fn dimensions(&self) -> Vector
Get the dimensions of the grid, as a
Vector
. The dimensions of
must be >= 0.Source§fn outer_bound(&self) -> Location
fn outer_bound(&self) -> Location
Get the outer bound of the grid; that is, the location for which all
valid locations in the grid have
row < outer.row && column < outer.column
Source§fn num_columns(&self) -> Columns
fn num_columns(&self) -> Columns
Get the width of the grid, in
Columns
.Source§fn root_row(&self) -> Row
fn root_row(&self) -> Row
Return the index of the topmost row of this grid. For most grids,
this is 0, but some grids may include negatively indexed locations,
or even offsets.
Source§fn root_column(&self) -> Column
fn root_column(&self) -> Column
Return the index of the leftmost column of this grid. For most grids,
this is 0, but some grids may include negatively indexed locations,
or even offsets.
Source§fn root_component<C>(&self) -> Cwhere
C: Component,
fn root_component<C>(&self) -> Cwhere
C: Component,
Return the index of the leftmost column or topmost row of this grid.
Source§fn row_range(&self) -> ComponentRange<Row>
fn row_range(&self) -> ComponentRange<Row>
Get a range iterator over all the
Row
indexes in this gridSource§fn column_range(&self) -> ComponentRange<Column>
fn column_range(&self) -> ComponentRange<Column>
Get a range iterator over all the
Column
indexes in this gridSource§fn range<C>(&self) -> ComponentRange<C>where
C: Component,
fn range<C>(&self) -> ComponentRange<C>where
C: Component,
Get a range iterator over the row or column indexes
Source§fn check_component<C>(&self, c: C) -> Result<C, RangeError<C>>where
C: Component,
fn check_component<C>(&self, c: C) -> Result<C, RangeError<C>>where
C: Component,
Source§fn check_row(&self, row: impl Into<Row>) -> Result<Row, RangeError<Row>>
fn check_row(&self, row: impl Into<Row>) -> Result<Row, RangeError<Row>>
Check that a
Row
is inside the bounds described by this grid.
Returns the component if it’s inside the bounds, or an error
describing the violated boundary if not. This function is intended
to help write more expressive code; ie,
grid.check_row(10).and_then(|row| ...)
.Source§fn check_column(
&self,
column: impl Into<Column>,
) -> Result<Column, RangeError<Column>>
fn check_column( &self, column: impl Into<Column>, ) -> Result<Column, RangeError<Column>>
Check that a
Column
is inside the bounds described by this grid.
Returns the component if it’s inside the bounds, or an error
describing the violated boundary if not. This function is intended
to help write more expressive code; ie,
grid.check_column(10).and_then(|row| ...)
.Source§fn component_in_bounds<C>(&self, c: C) -> boolwhere
C: Component,
fn component_in_bounds<C>(&self, c: C) -> boolwhere
C: Component,
Source§fn row_in_bounds(&self, row: impl Into<Row>) -> bool
fn row_in_bounds(&self, row: impl Into<Row>) -> bool
Returns true if a
Row
is inside the bounds described
by this grid.Source§fn column_in_bounds(&self, column: impl Into<Column>) -> bool
fn column_in_bounds(&self, column: impl Into<Column>) -> bool
Returns true if a
Column
is inside the bounds described
by this grid.Source§fn check_location(
&self,
location: impl LocationLike,
) -> Result<Location, BoundsError>
fn check_location( &self, location: impl LocationLike, ) -> Result<Location, BoundsError>
Check that a location is inside the bounds of this grid. Read more
Source§fn location_in_bounds(&self, location: impl LocationLike) -> bool
fn location_in_bounds(&self, location: impl LocationLike) -> bool
Returns true if a locaton is inside the bounds of this grid.
Source§impl<G: GridMut> GridMut for ZeroRoot<G>
impl<G: GridMut> GridMut for ZeroRoot<G>
Source§unsafe fn get_unchecked_mut(&mut self, location: Location) -> &mut Self::Item
unsafe fn get_unchecked_mut(&mut self, location: Location) -> &mut Self::Item
Get a mutable 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_mut
operations
on the underlying storage, where relevant / possible. Read moreSource§fn get_mut(
&mut self,
location: impl LocationLike,
) -> Result<&mut Self::Item, BoundsError>
fn get_mut( &mut self, location: impl LocationLike, ) -> Result<&mut 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.
Source§impl<G: GridSetter> GridSetter for ZeroRoot<G>
impl<G: GridSetter> GridSetter for ZeroRoot<G>
Source§unsafe fn replace_unchecked(
&mut self,
location: Location,
value: Self::Item,
) -> Self::Item
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. Read moreSource§unsafe fn set_unchecked(&mut self, location: Location, value: Self::Item)
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>
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>
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.Auto Trait Implementations§
impl<G> Freeze for ZeroRoot<G>where
G: Freeze,
impl<G> RefUnwindSafe for ZeroRoot<G>where
G: RefUnwindSafe,
impl<G> Send for ZeroRoot<G>where
G: Send,
impl<G> Sync for ZeroRoot<G>where
G: Sync,
impl<G> Unpin for ZeroRoot<G>where
G: Unpin,
impl<G> UnwindSafe for ZeroRoot<G>where
G: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more