# Struct cassowary::Solver
[−]
[src]

pub struct Solver { /* fields omitted */ }

A constraint solver using the Cassowary algorithm. For proper usage please see the top level crate documentation.

## Methods

`impl Solver`

[src]

`fn new() -> Solver`

Construct a new solver.

`fn add_constraints<'a, I: IntoIterator<Item = &'a Constraint>>(`

&mut self,

constraints: I

) -> Result<(), AddConstraintError>

&mut self,

constraints: I

) -> Result<(), AddConstraintError>

`fn add_constraint(`

&mut self,

constraint: Constraint

) -> Result<(), AddConstraintError>

&mut self,

constraint: Constraint

) -> Result<(), AddConstraintError>

Add a constraint to the solver.

`fn remove_constraint(`

&mut self,

constraint: &Constraint

) -> Result<(), RemoveConstraintError>

&mut self,

constraint: &Constraint

) -> Result<(), RemoveConstraintError>

Remove a constraint from the solver.

`fn has_constraint(&self, constraint: &Constraint) -> bool`

Test whether a constraint has been added to the solver.

`fn add_edit_variable(`

&mut self,

v: Variable,

strength: f64

) -> Result<(), AddEditVariableError>

&mut self,

v: Variable,

strength: f64

) -> Result<(), AddEditVariableError>

Add an edit variable to the solver.

This method should be called before the `suggest_value`

method is
used to supply a suggested value for the given edit variable.

`fn remove_edit_variable(`

&mut self,

v: Variable

) -> Result<(), RemoveEditVariableError>

&mut self,

v: Variable

) -> Result<(), RemoveEditVariableError>

Remove an edit variable from the solver.

`fn has_edit_variable(&self, v: &Variable) -> bool`

Test whether an edit variable has been added to the solver.

`fn suggest_value(`

&mut self,

variable: Variable,

value: f64

) -> Result<(), SuggestValueError>

&mut self,

variable: Variable,

value: f64

) -> Result<(), SuggestValueError>

Suggest a value for the given edit variable.

This method should be used after an edit variable has been added to the solver in order to suggest the value for that variable.

`fn fetch_changes(&mut self) -> &[(Variable, f64)]`

Fetches all changes to the values of variables since the last call to this function.

The list of changes returned is not in a specific order. Each change comprises the variable changed and the new value of that variable.

`fn reset(&mut self)`

Reset the solver to the empty starting condition.

This method resets the internal solver state to the empty starting condition, as if no constraints or edit variables have been added. This can be faster than deleting the solver and creating a new one when the entire system must change, since it can avoid unnecessary heap (de)allocations.

`fn get_value(&self, v: Variable) -> f64`

Get the stored value for a variable.

Normally values should be retrieved and updated using `fetch_changes`

, but
this method can be used for debugging or testing.