Struct ZeroRoot

Source
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: GridBounds> ZeroRoot<G>

Source

pub fn new(grid: G) -> Self

Source§

impl<G> ZeroRoot<G>

Source

pub fn into_inner(self) -> G

Trait Implementations§

Source§

impl<G> AsMut<G> for ZeroRoot<G>

Source§

fn as_mut(&mut self) -> &mut G

Converts this type into a mutable reference of the (usually inferred) input type.
Source§

impl<G> AsRef<G> for ZeroRoot<G>

Source§

fn as_ref(&self) -> &G

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<G: Clone> Clone for ZeroRoot<G>

Source§

fn clone(&self) -> ZeroRoot<G>

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<G: Debug> Debug for ZeroRoot<G>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<G: Grid> Grid for ZeroRoot<G>

Source§

type Item = <G as Grid>::Item

The item type stored in the grid
Source§

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

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,

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 rows(&self) -> View<'_, Self, Row>

Get a view of a grid’s rows. See [View] for details.
Source§

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,

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>

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>

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,

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

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

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>
where F: Fn(&Self::Item) -> T, T: Display,

Make a grid Displayable, using a function that defines how each of its cells are printed. For each row, the adapter simply prints each cell in the row, followed by a newline. Read more
Source§

impl<G: GridBounds> GridBounds for ZeroRoot<G>

Source§

fn dimensions(&self) -> Vector

Get the dimensions of the grid, as a Vector. The dimensions of must be >= 0.
Source§

fn root(&self) -> Location

Return the root location (ie, the top left) of the grid. All valid locations on the grid have location >= root. For most grids, this can just be Location::zero
Source§

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_rows(&self) -> Rows

Get the height of the grid in Rows.
Source§

fn num_columns(&self) -> Columns

Get the width of the grid, in Columns.
Source§

fn dimension<C>(&self) -> C
where C: Component,

Get the height or width of this grid.
Source§

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

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) -> C
where C: Component,

Return the index of the leftmost column or topmost row of this grid.
Source§

fn row_range(&self) -> ComponentRange<Row>

Get a range iterator over all the Row indexes in this grid
Source§

fn column_range(&self) -> ComponentRange<Column>

Get a range iterator over all the Column indexes in this grid
Source§

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,

Check that a Row or 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_component(Row(10)).and_then(|row| ...).
Source§

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

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) -> bool
where C: Component,

Returns true if a Row or Column is inside the bounds described by this grid.
Source§

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

Returns true if a Column is inside the bounds described by this grid.
Source§

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

Returns true if a locaton is inside the bounds of this grid.
Source§

impl<G: GridMut> GridMut for ZeroRoot<G>

Source§

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

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>

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. Read more
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. Read more
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.

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.