Skip to main content

Grid

Struct Grid 

Source
pub struct Grid<T> { /* private fields */ }
Expand description

A width × height grid of T, stored row-major.

Indexing is (x, y): grid[(x, y)] reads the cell at column x, row y.

Implementations§

Source§

impl<T: Clone> Grid<T>

Source

pub fn new(width: usize, height: usize, value: T) -> Self

Creates a grid filled with value.

§Panics

Panics if either dimension is 0.

Source§

impl<T> Grid<T>

Source

pub fn from_vec(width: usize, height: usize, data: Vec<T>) -> Self

Wraps an existing row-major buffer.

§Panics

Panics if data.len() != width * height or either dimension is 0.

Source

pub fn width(&self) -> usize

Grid width in cells.

Source

pub fn height(&self) -> usize

Grid height in cells.

Source

pub fn len(&self) -> usize

Total number of cells (width * height).

Source

pub fn is_empty(&self) -> bool

Always false: grids have positive dimensions by construction.

Source

pub fn idx(&self, x: usize, y: usize) -> usize

Flat index of (x, y).

Callers holding flat indices (e.g. from Self::as_slice) can map back with Self::coords.

Source

pub fn coords(&self, idx: usize) -> (usize, usize)

(x, y) coordinates of a flat index.

Source

pub fn as_slice(&self) -> &[T]

The underlying row-major buffer.

Source

pub fn as_mut_slice(&mut self) -> &mut [T]

The underlying row-major buffer, mutably.

Source

pub fn into_vec(self) -> Vec<T>

Consumes the grid, returning the row-major buffer.

Source

pub fn iter(&self) -> Iter<'_, T> ⓘ

Iterates over all cells in row-major order.

Source

pub fn iter_mut(&mut self) -> IterMut<'_, T> ⓘ

Iterates mutably over all cells in row-major order.

Trait Implementations§

Source§

impl<T: Clone> Clone for Grid<T>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<T: Debug> Debug for Grid<T>

Source§

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

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

impl<T> Index<(usize, usize)> for Grid<T>

Source§

type Output = T

The returned type after indexing.
Source§

fn index(&self, (x, y): (usize, usize)) -> &T

Performs the indexing (container[index]) operation. Read more
Source§

impl<T> IndexMut<(usize, usize)> for Grid<T>

Source§

fn index_mut(&mut self, (x, y): (usize, usize)) -> &mut T

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl<'a, T> IntoIterator for &'a Grid<T>

Source§

type Item = &'a T

The type of the elements being iterated over.
Source§

type IntoIter = Iter<'a, T>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<T: PartialEq> PartialEq for Grid<T>

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl<T: PartialEq> StructuralPartialEq for Grid<T>

Auto Trait Implementations§

§

impl<T> Freeze for Grid<T>
where Vec<T>: Freeze,

§

impl<T> RefUnwindSafe for Grid<T>
where Vec<T>: RefUnwindSafe,

§

impl<T> Send for Grid<T>
where Vec<T>: Send,

§

impl<T> Sync for Grid<T>
where Vec<T>: Sync,

§

impl<T> Unpin for Grid<T>
where Vec<T>: Unpin,

§

impl<T> UnsafeUnpin for Grid<T>
where Vec<T>: UnsafeUnpin,

§

impl<T> UnwindSafe for Grid<T>
where Vec<T>: 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.