pub struct Grid<T> { /* private fields */ }Expand description
A width × height rectangle of cells, stored row-major. The cell count
always equals width * height; deserialising checks it.
Implementations§
Source§impl<T> Grid<T>
impl<T> Grid<T>
Sourcepub fn from_cells(width: u16, height: u16, cells: Vec<T>) -> Option<Self>
pub fn from_cells(width: u16, height: u16, cells: Vec<T>) -> Option<Self>
Builds a grid from row-major cells; None if the count is not
width * height.
Sourcepub fn filled(width: u16, height: u16, value: T) -> Selfwhere
T: Clone,
pub fn filled(width: u16, height: u16, value: T) -> Selfwhere
T: Clone,
A width × height grid with every cell set to value.
Sourcepub fn get_mut(&mut self, pos: Pos) -> Option<&mut T>
pub fn get_mut(&mut self, pos: Pos) -> Option<&mut T>
The cell at pos for writing, or None if out of bounds.
Sourcepub fn neighbors4(&self, pos: Pos) -> impl Iterator<Item = Pos> + '_
pub fn neighbors4(&self, pos: Pos) -> impl Iterator<Item = Pos> + '_
The in-bounds neighbours of pos, in Dir::ALL order.
Sourcepub fn positions(&self) -> impl Iterator<Item = Pos> + use<T>
pub fn positions(&self) -> impl Iterator<Item = Pos> + use<T>
Every position, row-major (the order of Grid::cells).
Trait Implementations§
Source§impl<'de, T> Deserialize<'de> for Grid<T>where
T: Deserialize<'de>,
impl<'de, T> Deserialize<'de> for Grid<T>where
T: Deserialize<'de>,
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
impl<T: Eq> Eq for Grid<T>
Source§impl<T> JsonSchema for Grid<T>where
T: JsonSchema,
impl<T> JsonSchema for Grid<T>where
T: JsonSchema,
Source§fn schema_id() -> Cow<'static, str>
fn schema_id() -> Cow<'static, str>
Returns a string that uniquely identifies the schema produced by this type. Read more
Source§fn json_schema(generator: &mut SchemaGenerator) -> Schema
fn json_schema(generator: &mut SchemaGenerator) -> Schema
Generates a JSON Schema for this type. Read more
Source§fn inline_schema() -> bool
fn inline_schema() -> bool
Whether JSON Schemas generated for this type should be included directly in parent schemas,
rather than being re-used where possible using the
$ref keyword. Read moreimpl<T: PartialEq> StructuralPartialEq for Grid<T>
Auto Trait Implementations§
impl<T> Freeze for Grid<T>
impl<T> RefUnwindSafe for Grid<T>where
T: RefUnwindSafe,
impl<T> Send for Grid<T>where
T: Send,
impl<T> Sync for Grid<T>where
T: Sync,
impl<T> Unpin for Grid<T>where
T: Unpin,
impl<T> UnsafeUnpin for Grid<T>
impl<T> UnwindSafe for Grid<T>where
T: 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