Crate cell_grid

Source
Expand description

A simple 2d grid container

§Example

use cell_grid::DynamicGrid;

// Create a new empty grid
let mut grid: DynamicGrid<i32> = DynamicGrid::new();

// Push rows
grid.push_row([1, 2]).unwrap();
grid.push_row([3, 4]).unwrap();

// Access by coordinate
assert_eq!(grid.get(0, 0), Some(&1));
assert_eq!(grid.get(1, 0), Some(&2));
assert_eq!(grid.get(0, 1), Some(&3));
assert_eq!(grid.get(1, 1), Some(&4));

// Iterate the content
assert_eq!(grid.cells().copied().collect::<Vec<_>>(), vec![1, 2, 3, 4]);
assert_eq!(grid.rows().collect::<Vec<_>>(), vec![&[1, 2], &[3, 4]]);

It is also possible to:

§Features

  • std: (enabled by default) enable use of the standard library. Must be disabled for no_std crates.

Structs§

CoordDeprecated
A coordinate of a grid
DynamicGrid
A row-major 2d grid
GridDeprecated
A 2d fixed-size grid containers for cells of type T
IncompatibleRowSize
Error returned by DynamicGrid::push_row if the length of the row being pushed is incompatible with the current width of the grid
RectDeprecated
A rectangle of coordinates