Skip to main content

Grid2D

Struct Grid2D 

Source
pub struct Grid2D<T: Copy + Default> { /* private fields */ }
Expand description

A double-buffered 2D grid of cells, stored row-major.

A step reads Self::current and writes Self::next_mut, then Self::swap makes the next side current.

Implementations§

Source§

impl<T: Copy + Default> Grid2D<T>

Source

pub fn new(width: u32, height: u32) -> Self

Creates a width by height grid with every cell at T::default() on both sides.

Source

pub fn width(&self) -> u32

Width in cells.

Source

pub fn height(&self) -> u32

Height in cells.

Source

pub fn heap_bytes(&self) -> usize

Heap memory held by both sides, in bytes.

Source

pub fn len(&self) -> usize

Number of cells.

Source

pub fn is_empty(&self) -> bool

Returns whether the grid has no cells.

Source

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

Cells of the current side.

Source

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

Returns the current side mutably, for initialisation.

A step writes through Self::next_mut.

Source

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

Returns the next side for a step to write.

Source

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

Returns the current side to read and the next side to write, as one split borrow.

Source

pub fn swap(&mut self)

Makes the next side current by swapping the two buffers, copying no cells.

Trait Implementations§

Source§

impl<T: Copy + Default> Debug for Grid2D<T>

Prints the grid’s size, not its cells.

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

§

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

§

impl<T> UnwindSafe for Grid2D<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> 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 = !

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

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSync for T
where T: Sync,