Struct takuzu::Grid [] [src]

pub struct Grid { /* fields omitted */ }

An opaque container for takuzu grid manipulation.

It provides the internal logic and other convenience functions. To create a Grid you can:

  • create an empty one yourself with Grid::new(size).
  • use the FromStr trait, e.g. by calling .parse() on a string.
  • use the Source trait, i.e. by calling .source() on any Read implementor.

The Grid type does not maintain any internal invariant. That is, you can modify the grid as you like and break the rules. Such grids will not be solved, though.

Methods

impl Grid
[src]

Creates an new empty grid of a given size.

Errors

Returns an error if the size is an odd number or 0.

Returns the number of rows/columns of the array.

Extracts a slice containing the entire underlying array.

Extracts a mutable slice of the entire underlying array.

Returns true if the grid contains no Empty cell.

Verifies that the grid does not currently violate any of the rules.

Returns true if the grid is legal.

Verifies that a certain cell does not violate any of the rules.

Returns true if the value is legal.

Returns the index of the first Empty cell or None if the grid is filled.

Solves the grid using both rules logic and a backtracking algorithm, and returns an array containing the solution(s).

If no solution exists, an empty array is returned.

Errors

Returns an error before any attempt at solving if the grid breaks any of the rules.

Use the is_legal() method to know if the grid will trigger an Err.

Suitable for printing in terminals.

Encodes the grid as a printable string containing ANSI escape codes. The grid is compared to a reference grid. The cells that differ from the reference will be displayed in color.

Warning

A red-colored cell signals that a 0 or a 1 from the reference grid was overwritten. (Which, if reference is the original grid and self is a solution, should never happen.)

Trait Implementations

impl Clone for Grid
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl Debug for Grid
[src]

Formats the value using the given formatter.

impl Eq for Grid
[src]

impl PartialEq for Grid
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl Display for Grid
[src]

Formats the value using the given formatter. Read more

impl Index<(usize, usize)> for Grid
[src]

The returned type after indexing

The method for the indexing (container[index]) operation

impl IndexMut<(usize, usize)> for Grid
[src]

The method for the mutable indexing (container[index]) operation

impl FromStr for Grid
[src]

The associated error which can be returned from parsing.

Parses a string s to return a value of this type. Read more