gridlife

Struct Grid

Source
pub struct Grid<T> {
    pub width: usize,
    pub height: usize,
    pub cells: Vec<T>,
    pub dead_glyph: char,
    pub alive_glyph: char,
}
Expand description

Grid holds the state for a Conways game of life

Fields§

§width: usize

The width of the grid to be created

§height: usize

The height of the grid to be created

§cells: Vec<T>

The state of the grid in terms of what cells are alive and dead in automaton

§dead_glyph: char

What character glyph should be used to display a dead population

§alive_glyph: char

What character glyph should be used to display an alive population

Implementations§

Source§

impl Grid<CellState>

Source

pub fn new_empty(width: usize, height: usize) -> Self

Create a new Grid of a given width and height. It will default to X for alive glyph and for dead glyph

Source

pub fn new_random(width: usize, height: usize) -> Self

Generate a new Grid of a given width and height It will be populated with a random distribution of Alive/Dead cells The default glyphs of X for alive and for dead.

Source

pub fn new_random_custom_glyphs( width: usize, height: usize, alive_glyph: char, dead_glyph: char, ) -> Self

Generate a new Grid of a given width and height It will be populated with a random distribution of Alive/Dead cells The glyphs can be overriddne with alive_glyph and dead_glyph

Source

pub fn update_states(&mut self) -> u32

Re-generates the state of the Grid cells based on the rules of Conways game of life

Trait Implementations§

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 Default for Grid<CellState>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Display for Grid<CellState>

Source§

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

Formats the value using the given formatter. Read more

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> UnwindSafe for Grid<T>
where 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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.