pub struct DynamicConstraint { /* private fields */ }
Expand description
A Constraint that contains a vector of trait objects representing constraints and verifies all of them. This is more flexible than a CompositeConstraint, but also less efficient, since it needs dynamic dispatch.
Implementations§
Source§impl DynamicConstraint
impl DynamicConstraint
Sourcepub fn with_children(
constraints: Vec<Box<dyn CloneConstraint>>,
) -> DynamicConstraint
pub fn with_children( constraints: Vec<Box<dyn CloneConstraint>>, ) -> DynamicConstraint
Creates a new dynamic constraint from the given child constraints. The created constraint is defined to be satisfied if all children are satisfied.
Sourcepub fn new() -> DynamicConstraint
pub fn new() -> DynamicConstraint
Creates a new dynamic constraint without any child constraint. Children can be added later using DynamicConstraint::add.
Sourcepub fn add(&mut self, constraint: impl CloneConstraint + 'static)
pub fn add(&mut self, constraint: impl CloneConstraint + 'static)
Adds a CloneConstraint to this dynamic constraint as a child. It is wrapped in a trait object.
Trait Implementations§
Source§impl Clone for DynamicConstraint
impl Clone for DynamicConstraint
Source§impl Constraint for DynamicConstraint
impl Constraint for DynamicConstraint
Source§fn check(&self, grid: &SudokuGrid) -> bool
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
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
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 moreSource§fn get_groups(&self, grid: &SudokuGrid) -> Vec<Group> ⓘ
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
Source§impl Default for DynamicConstraint
impl Default for DynamicConstraint
Source§fn default() -> DynamicConstraint
fn default() -> DynamicConstraint
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for DynamicConstraint
impl !RefUnwindSafe for DynamicConstraint
impl !Send for DynamicConstraint
impl !Sync for DynamicConstraint
impl Unpin for DynamicConstraint
impl !UnwindSafe for DynamicConstraint
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<C> CloneConstraint for Cwhere
C: Constraint + Clone + 'static,
impl<C> CloneConstraint for Cwhere
C: Constraint + Clone + 'static,
Source§fn clone_box(&self) -> Box<dyn CloneConstraint>
fn clone_box(&self) -> Box<dyn CloneConstraint>
Clones a trait object of this constraint.