cassowary

Struct Solver

Source
pub struct Solver { /* private fields */ }
Expand description

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

Implementations§

Source§

impl Solver

Source

pub fn new() -> Solver

Construct a new solver.

Source

pub fn add_constraints<'a, I: IntoIterator<Item = &'a Constraint>>( &mut self, constraints: I, ) -> Result<(), AddConstraintError>

Source

pub fn add_constraint( &mut self, constraint: Constraint, ) -> Result<(), AddConstraintError>

Add a constraint to the solver.

Source

pub fn remove_constraint( &mut self, constraint: &Constraint, ) -> Result<(), RemoveConstraintError>

Remove a constraint from the solver.

Source

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

Test whether a constraint has been added to the solver.

Source

pub fn add_edit_variable( &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.

Source

pub fn remove_edit_variable( &mut self, v: Variable, ) -> Result<(), RemoveEditVariableError>

Remove an edit variable from the solver.

Source

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

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

Source

pub fn suggest_value( &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.

Source

pub 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.

Source

pub 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.

Source

pub 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.

Auto Trait Implementations§

§

impl Freeze for Solver

§

impl !RefUnwindSafe for Solver

§

impl !Send for Solver

§

impl !Sync for Solver

§

impl Unpin for Solver

§

impl !UnwindSafe for Solver

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> 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, 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.