CompositeConstraint

Struct CompositeConstraint 

Source
pub struct CompositeConstraint<C1, C2>
where C1: Constraint + Clone + 'static, C2: Constraint + Clone + 'static,
{ /* private fields */ }
Expand description

A Constraint which simultaneously enforces two other constraints. This allows the construction of complex constraints by nesting composite constraints.

As an example, a constraint with DefaultConstraint, DiagonalsConstraint, and KnightsMoveConstraint would be constructed as follows:

use sudoku_variants::constraint::{
    CompositeConstraint,
    DefaultConstraint,
    DiagonalsConstraint,
    KnightsMoveConstraint
};

let constraint = CompositeConstraint::new(
    DefaultConstraint,
    CompositeConstraint::new(
        DiagonalsConstraint,
        KnightsMoveConstraint
    )
);

The advantage of using this over a DynamicConstraint is that it is statically known which types of constraints are used, so no dynamic dispatch is necessary. On the contrary, a CompositeConstraint is less flexible.

Implementations§

Source§

impl<C1, C2> CompositeConstraint<C1, C2>
where C1: Constraint + Clone + 'static, C2: Constraint + Clone + 'static,

Source

pub fn new(c1: C1, c2: C2) -> CompositeConstraint<C1, C2>

Creates a new composite constraint from the two child consraints which will be enforced.

Trait Implementations§

Source§

impl<C1, C2> Clone for CompositeConstraint<C1, C2>
where C1: Constraint + Clone + 'static + Clone, C2: Constraint + Clone + 'static + Clone,

Source§

fn clone(&self) -> CompositeConstraint<C1, C2>

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

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

Performs copy-assignment from source. Read more
Source§

impl<C1, C2> Constraint for CompositeConstraint<C1, C2>
where C1: Constraint + Clone + 'static, C2: Constraint + Clone + 'static,

Source§

fn check(&self, grid: &SudokuGrid) -> bool

Checks whether the given SudokuGrid matches this constraint, that is, every cell matches this constraint. By default, this runs check_cell on every cell of the grid, which may be inefficient, so custom implementations may be advantageous.
Source§

fn check_cell(&self, grid: &SudokuGrid, column: usize, row: usize) -> bool

Checks whether the cell at the given position in the SudokuGrid fulfills the constraint. This is the same as calling check_number with the same coordinates and the number which is actually filled in that cell. If the cell is empty, this function always returns true.
Source§

fn check_number( &self, grid: &SudokuGrid, column: usize, row: usize, number: usize, ) -> bool

Checks whether the given number would fit into the cell specified by column and row into the grid without violating this constraint. This function does not have to check whether number is actually a valid number for this grid (i.e. in the interval [1, size]). If you require this guarantee, use Sudoku::is_valid_number instead. Read more
Source§

fn get_groups(&self, grid: &SudokuGrid) -> Vec<Group>

Gets a vector of all groups that are defined by this constraint. A group is a set of cells which may not contain repeated numbers. As an example, the BlockConstraint defines each block as a group. Some constraints, such as the KingsMoveConstraint, do not have groups. In this particular case, a cell removed by a kings-move to the top-left may be the same as one to the bottom-right, so the cells removed by a kings-move from any particular cell cannot form a group. Such constraints should return an empty vector here. Read more

Auto Trait Implementations§

§

impl<C1, C2> Freeze for CompositeConstraint<C1, C2>
where C1: Freeze, C2: Freeze,

§

impl<C1, C2> RefUnwindSafe for CompositeConstraint<C1, C2>

§

impl<C1, C2> Send for CompositeConstraint<C1, C2>
where C1: Send, C2: Send,

§

impl<C1, C2> Sync for CompositeConstraint<C1, C2>
where C1: Sync, C2: Sync,

§

impl<C1, C2> Unpin for CompositeConstraint<C1, C2>
where C1: Unpin, C2: Unpin,

§

impl<C1, C2> UnwindSafe for CompositeConstraint<C1, C2>
where C1: UnwindSafe, C2: 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<C> CloneConstraint for C
where C: Constraint + Clone + 'static,

Source§

fn clone_box(&self) -> Box<dyn CloneConstraint>

Clones a trait object of this constraint.
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 = 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