[−][src]Struct gridly_grids::VecGrid
A grid that stores its elements in a Vec<T>
, in row-major order.
Methods
impl<T> VecGrid<T>
[src]
pub fn new_fill_with(
dimensions: impl VectorLike,
gen: impl Fn() -> T
) -> Option<Self>
[src]
dimensions: impl VectorLike,
gen: impl Fn() -> T
) -> Option<Self>
Create a new VecGrid
, filled with elements by repeatedly calling a
function. The function is called once per cell in an unspecified order;
use [new_with
] if you want to have per-cell initialization logic.
Returns the grid, or None
if the dimensions
were invalid.
Example:
use gridly_grids::VecGrid; use gridly::prelude::*; let grid = VecGrid::new_fill_with((Rows(2), Columns(2)), || "Hello, World!".to_string()).unwrap(); assert_eq!(grid[(1, 0)], "Hello, World!")
See also [new
] for filling a grid with a type's [default] value, and
[new_fill
] for filling a grid with a clone of a value.
pub fn new_with(
dimensions: impl VectorLike,
gen: impl FnMut(&Location) -> T
) -> Option<Self>
[src]
dimensions: impl VectorLike,
gen: impl FnMut(&Location) -> T
) -> Option<Self>
Create a new VecGrid
by calling a function with the location of each cell
in the grid, storing the return value of that function in that cell.
The function is called once per cell in an unspecified order; users should not rely on it being called in row-major order.
Returns the grid, or None
if the dimensions
were invalid.
Example:
use gridly_grids::VecGrid; use gridly::prelude::*; let grid = VecGrid::new_with((Rows(2), Columns(2)), |loc| loc.row.0 + loc.column.0).unwrap(); assert_eq!(grid.get((0, 0)), Ok(&0)); assert_eq!(grid.get((0, 1)), Ok(&1)); assert_eq!(grid.get((1, 0)), Ok(&1)); assert_eq!(grid.get((1, 1)), Ok(&2)); assert!(grid.get((1, 2)).is_err());
pub fn fill_with(&mut self, gen: impl Fn() -> T)
[src]
Fill every cell in the grid with the values produced by repeatedly
calling gen
. Called in an unspecified order.
Example
use gridly_grids::VecGrid; use gridly::prelude::*; let mut grid: VecGrid<isize> = VecGrid::new((Rows(2), Columns(2))).unwrap(); grid.fill_with(|| 3); assert_eq!(grid.get((0, 0)), Ok(&3)); assert_eq!(grid.get((0, 1)), Ok(&3)); assert_eq!(grid.get((1, 0)), Ok(&3)); assert_eq!(grid.get((1, 1)), Ok(&3)); assert!(grid.get((1, 2)).is_err());
impl<T: Default> VecGrid<T>
[src]
pub fn new(dimensions: impl VectorLike) -> Option<Self>
[src]
Create a new VecGrid
filled with the default value of T
in each cell
Example
use gridly_grids::VecGrid; use gridly::prelude::*; let grid: VecGrid<isize> = VecGrid::new((Rows(2), Columns(2))).unwrap(); assert_eq!(grid.get((0, 0)), Ok(&0)); assert_eq!(grid.get((0, 1)), Ok(&0)); assert_eq!(grid.get((1, 0)), Ok(&0)); assert_eq!(grid.get((1, 1)), Ok(&0)); assert!(grid.get((1, 2)).is_err());
pub fn clear(&mut self)
[src]
Replace all the cells in the grid with the default value
Example
use gridly_grids::VecGrid; use gridly::prelude::*; let mut grid = VecGrid::new_fill((Rows(2), Columns(2)), &5).unwrap(); grid.clear(); assert_eq!(grid.get((0, 0)), Ok(&0)); assert_eq!(grid.get((0, 1)), Ok(&0)); assert_eq!(grid.get((1, 0)), Ok(&0)); assert_eq!(grid.get((1, 1)), Ok(&0)); assert!(grid.get((1, 2)).is_err());
impl<T: Clone> VecGrid<T>
[src]
pub fn new_fill(dimensions: impl VectorLike, value: &T) -> Option<Self>
[src]
Create a new VecGrid
filled with clones of value
Example
use gridly_grids::VecGrid; use gridly::prelude::*; let grid = VecGrid::new_fill((Rows(2), Columns(2)), &"Hello").unwrap(); assert_eq!(grid.get((0, 0)), Ok(&"Hello")); assert_eq!(grid.get((0, 1)), Ok(&"Hello")); assert_eq!(grid.get((1, 0)), Ok(&"Hello")); assert_eq!(grid.get((1, 1)), Ok(&"Hello")); assert!(grid.get((1, 2)).is_err());
pub fn fill(&mut self, value: &T)
[src]
Fill every element in the grid with clones of value
Example
use gridly_grids::VecGrid; use gridly::prelude::*; let mut grid = VecGrid::new((Rows(2), Columns(2))).unwrap(); grid.fill(&"Hello"); assert_eq!(grid.get((0, 0)), Ok(&"Hello")); assert_eq!(grid.get((0, 1)), Ok(&"Hello")); assert_eq!(grid.get((1, 0)), Ok(&"Hello")); assert_eq!(grid.get((1, 1)), Ok(&"Hello")); assert!(grid.get((1, 2)).is_err());
Trait Implementations
impl<T: Clone> Clone for VecGrid<T>
[src]
impl<T, L: LocationLike> Index<L> for VecGrid<T>
[src]
impl<T, L: LocationLike> IndexMut<L> for VecGrid<T>
[src]
impl<T: Debug> Debug for VecGrid<T>
[src]
impl<T> BaseGridBounds for VecGrid<T>
[src]
impl<T> BaseGridSetter for VecGrid<T>
[src]
unsafe fn replace_unchecked(&mut self, location: &Location, value: T) -> T
[src]
unsafe fn set_unchecked(&mut self, location: &Location, value: T)
[src]
impl<T> BaseGrid for VecGrid<T>
[src]
type Item = T
unsafe fn get_unchecked(&self, location: &Location) -> &T
[src]
impl<T> BaseGridMut for VecGrid<T>
[src]
unsafe fn get_unchecked_mut(&mut self, location: &Location) -> &mut T
[src]
Auto Trait Implementations
impl<T> Send for VecGrid<T> where
T: Send,
T: Send,
impl<T> Unpin for VecGrid<T> where
T: Unpin,
T: Unpin,
impl<T> Sync for VecGrid<T> where
T: Sync,
T: Sync,
impl<T> UnwindSafe for VecGrid<T> where
T: UnwindSafe,
T: UnwindSafe,
impl<T> RefUnwindSafe for VecGrid<T> where
T: RefUnwindSafe,
T: RefUnwindSafe,
Blanket Implementations
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From<T> for T
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<G> GridBounds for G where
G: BaseGridBounds,
[src]
G: BaseGridBounds,
fn outer_root(&self) -> Location
[src]
fn num_rows(&self) -> Rows
[src]
fn num_columns(&self) -> Columns
[src]
fn dimension<C>(&self) -> C where
C: Component,
[src]
C: Component,
fn root_row(&self) -> Row
[src]
fn root_column(&self) -> Column
[src]
fn root_component<C>(&self) -> C where
C: Component,
[src]
C: Component,
fn range<C>(&self) -> ComponentRange<C> where
C: Component,
[src]
C: Component,
fn row_range(&self) -> ComponentRange<Row>
[src]
fn column_range(&self) -> ComponentRange<Column>
[src]
fn check_component<C>(&self, c: C) -> Result<C, RangeError<C>> where
C: Component,
[src]
C: Component,
fn check_row(&self, row: impl Into<Row>) -> Result<Row, RangeError<Row>>
[src]
fn check_column(
&self,
column: impl Into<Column>
) -> Result<Column, RangeError<Column>>
[src]
&self,
column: impl Into<Column>
) -> Result<Column, RangeError<Column>>
fn component_in_bounds<C>(&self, c: C) -> bool where
C: Component,
[src]
C: Component,
fn row_in_bounds(&self, row: impl Into<Row>) -> bool
[src]
fn column_in_bounds(&self, column: impl Into<Column>) -> bool
[src]
fn check_location(
&self,
location: impl LocationLike
) -> Result<Location, BoundsError>
[src]
&self,
location: impl LocationLike
) -> Result<Location, BoundsError>
fn location_in_bounds(&self, location: impl LocationLike) -> bool
[src]
impl<G> GridSetter for G where
G: BaseGridSetter,
<G as BaseGrid>::Item: Sized,
[src]
G: BaseGridSetter,
<G as BaseGrid>::Item: Sized,
fn replace(
&mut self,
location: impl LocationLike,
value: Self::Item
) -> Result<Self::Item, BoundsError>
[src]
&mut self,
location: impl LocationLike,
value: Self::Item
) -> Result<Self::Item, BoundsError>
fn set(
&mut self,
location: impl LocationLike,
value: Self::Item
) -> Result<(), BoundsError>
[src]
&mut self,
location: impl LocationLike,
value: Self::Item
) -> Result<(), BoundsError>
impl<G> Grid for G where
G: BaseGrid,
[src]
G: BaseGrid,
fn get(&self, location: impl LocationLike) -> Result<&Self::Item, BoundsError>
[src]
fn view<T>(&self) -> View<Self, T> where
T: Component,
[src]
T: Component,
fn rows(&self) -> View<Self, Row>
[src]
fn columns(&self) -> View<Self, Column>
[src]
unsafe fn single_view_unchecked<T>(&self, index: T) -> SingleView<Self, T> where
T: Component,
[src]
T: Component,
unsafe fn row_unchecked(&self, row: Row) -> SingleView<Self, Row>
[src]
unsafe fn column_unchecked(&self, column: Column) -> SingleView<Self, Column>
[src]
fn single_view<T>(&self, index: T) -> Result<SingleView<Self, T>, RangeError<T>> where
T: Component,
[src]
T: Component,
fn row(
&self,
row: impl Into<Row>
) -> Result<SingleView<Self, Row>, RangeError<Row>>
[src]
&self,
row: impl Into<Row>
) -> Result<SingleView<Self, Row>, RangeError<Row>>
fn column(
&self,
column: impl Into<Column>
) -> Result<SingleView<Self, Column>, RangeError<Column>>
[src]
&self,
column: impl Into<Column>
) -> Result<SingleView<Self, Column>, RangeError<Column>>
impl<G> GridMut for G where
G: BaseGridMut,
[src]
G: BaseGridMut,
fn get_mut(
&mut self,
location: impl LocationLike
) -> Result<&mut Self::Item, BoundsError>
[src]
&mut self,
location: impl LocationLike
) -> Result<&mut Self::Item, BoundsError>