Struct Grid

Source
pub struct Grid {
    pub empty_cell_count: usize,
    pub solved: bool,
    /* private fields */
}
Expand description

Struct to represent a Sudoku grid, with fields for the representation as rows, columns and boxes, as well as the candidate matrix, an empty cell count field, and a boolean representing whether the puzzle has been solved.

Fields§

§empty_cell_count: usize§solved: bool

Implementations§

Source§

impl Grid

Source

pub fn new() -> Grid

Construct a new grid.

Source

pub fn rows(&self) -> &GridArray

Return a reference to the rows field.

Source

pub fn candidate_matrix(&self) -> &CandidateMatrix

Return a reference to the candidate_matrix field.

Source

pub fn get_cell(&self, cell: Coord) -> &Cell

Return a reference to the cell at cell.

Source

pub fn clear(&mut self, cell: Coord) -> Result<(), GridError>

Set cell to empty. Returns an error if called on a clue.

Source

pub fn update(&mut self, cell: Coord, val: u8) -> Result<(), GridError>

Update the value at cell to val. Returns an error if cell is a clue, or the update would result in another cell having zero valid candidates.

Source

pub fn remove_candidate(&mut self, cell: Coord, val: u8) -> bool

Remove candidate val from the set at cell.

Source

pub fn get_min_candidates_cell(&self) -> Coord

Returns the coordinates of the cell with the least valid candidates.

Source

pub fn candidates_at(&self, cell: Coord) -> Vec<u8>

Gets the candidates at cell as a vector.

Source

pub fn from_rows(rows: GridArray) -> Self

Constructs a Grid from a 2D array of Cells.

Source

pub fn set_clues(&mut self)

Set all Filled cells to Clues of the same value. Used in puzzle generation.

Source

pub fn reset_candidate_matrix(&mut self)

Trait Implementations§

Source§

impl Clone for Grid

Source§

fn clone(&self) -> Grid

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Grid

Source§

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

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

impl Default for Grid

Source§

fn default() -> Self

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

impl Display for Grid

Source§

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

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

impl From<[[Cell; 9]; 9]> for Grid

Enable conversion from 2D array of cells into Grid.

Source§

fn from(rows: GridArray) -> Grid

Converts to this type from the input type.
Source§

impl From<DisplayableGrid<Cell>> for Grid

Enable conversion from DisplayableGrid into Grid.

Source§

fn from(dg: DisplayableGrid<Cell>) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl Freeze for Grid

§

impl RefUnwindSafe for Grid

§

impl Send for Grid

§

impl Sync for Grid

§

impl Unpin for Grid

§

impl UnwindSafe for Grid

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

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V