Struct hotdrink_rs::model::ConstraintSystem[][src]

pub struct ConstraintSystem<T> { /* fields omitted */ }

A container for Components.

Implementations

impl<T> ConstraintSystem<T>[src]

pub fn new() -> Self[src]

Creates a new constraint system with no components.

pub fn add_component(&mut self, component: Component<T>)[src]

Adds a component to the constraint system.

pub fn remove_component(&mut self, name: &str) -> Option<Component<T>>[src]

Removes a component from the constraint system.

pub fn component<'s>(
    &self,
    name: &'s str
) -> Result<&Component<T>, NoSuchComponent<'s>>
[src]

Get a reference to the selected component.

pub fn component_mut<'s>(
    &mut self,
    name: &'s str
) -> Result<&mut Component<T>, NoSuchComponent<'s>>
[src]

Get a mutable reference to the selected component.

pub fn set_variable<'s>(
    &mut self,
    component: &'s str,
    variable: &'s str,
    value: impl Into<T>
) -> Result<(), NoSuchItem<'s>>
[src]

Updates the specified variable to the provided value.

pub fn variable<'a>(
    &self,
    component: &'a str,
    variable: &'a str
) -> Result<&Variable<Activation<T>>, NoSuchItem<'a>>
[src]

Returns the current value of the variable with name variable in component, if one exists.

pub fn value<'a>(
    &self,
    component: &'a str,
    variable: &'a str
) -> Result<Activation<T>, NoSuchItem<'a>>
[src]

Returns the current activation of the variable with name variable in component, if one exists.

pub fn update(&mut self) -> Result<(), PlanError> where
    T: Send + Sync + 'static + Debug
[src]

Attempts to enforces all constraints in every component that is modified. If no plan could be found, it will return a PlanError. This variant lets you specify a thread pool to run methods on.

pub fn par_update(
    &mut self,
    spawn: &mut impl ThreadPool
) -> Result<(), PlanError> where
    T: Send + Sync + 'static + Debug
[src]

Attempts to enforces all constraints in every component that is modified. If no plan could be found, it will return a PlanError. This variant lets you specify a thread pool to run methods on.

pub fn par_update_always(
    &mut self,
    spawn: &mut impl ThreadPool
) -> Result<(), PlanError> where
    T: Send + Sync + 'static + Debug
[src]

Attempts to enforces all constraints in every component, even if they have not been modified. If no plan could be found, it will return a PlanError.

pub fn subscribe<'a>(
    &mut self,
    component: &'a str,
    variable: &'a str,
    callback: impl for<'e> Fn(Event<'e, T, SolveError>) + Send + 'static
) -> Result<(), NoSuchItem<'a>> where
    T: 'static, 
[src]

Attaches a callback to a variable in a component, to be called when its status changes.

The events sent to the callback will be sent in an order matching an increase in generation. A pending event will always be sent before either ready or error, and a value from an earlier generation will never appear after one from a later generation. This ensures that the event always sends the most up-to-date value.

Examples

use hotdrink_rs::{model::ConstraintSystem, component, ret, Event};
let component = component! {
    component Comp {
        let x: i32 = 0, y: i32 = 0;
        constraint Eq {
            x_to_y(x: &i32) -> [y] = ret![*x];
            y_to_x(y: &i32) -> [x] = ret![*y];
        }
    }
};
let mut cs = ConstraintSystem::new();
cs.add_component(component);
cs.subscribe("Comp", "x", |e| match e {
    Event::Pending => {}
    Event::Ready(v) => assert_eq!(*v, 0),
    Event::Error(errors) => panic!("{:?}", errors),
});

pub fn unsubscribe<'a>(
    &mut self,
    component: &'a str,
    variable: &'a str
) -> Result<(), NoSuchItem<'a>>
[src]

Unsubscribe from a variable in the specified component to avoid receiving further events.

pub fn pin<'s>(
    &mut self,
    component: &'s str,
    variable: &'s str
) -> Result<(), NoSuchItem<'s>> where
    T: 'static, 
[src]

Pins a variable.

This adds a stay constraint to the specified variable, meaning that planning will attempt to avoid modifying it. The stay constraint can be remove with unpin.

pub fn unpin<'s>(
    &mut self,
    component: &'s str,
    variable: &'s str
) -> Result<(), NoSuchItem<'s>> where
    T: 'static, 
[src]

Unpins a variable.

This removes the stay constraint added by pin.

pub fn undo(&mut self) -> Result<(), NoMoreUndo>[src]

Undo the last change of the last modified component.

pub fn redo(&mut self) -> Result<(), NoMoreRedo>[src]

Redo the last change of the last modified component.

pub fn set_undo_limit(&mut self, limit: UndoLimit)[src]

Sets the undo-limit per component in the system.

pub fn enable_constraint<'a>(
    &mut self,
    component: &'a str,
    variable: &'a str
) -> Result<(), NoSuchItem<'a>>
[src]

Enables the specified constraint.

pub fn disable_constraint<'a>(
    &mut self,
    component: &'a str,
    variable: &'a str
) -> Result<(), NoSuchItem<'a>>
[src]

Disabled the specified constraint.

Trait Implementations

impl<T: Clone> Clone for ConstraintSystem<T>[src]

impl<T: Debug> Debug for ConstraintSystem<T>[src]

impl<T> Default for ConstraintSystem<T>[src]

impl<T: PartialEq> PartialEq<ConstraintSystem<T>> for ConstraintSystem<T>[src]

impl<T> StructuralPartialEq for ConstraintSystem<T>[src]

Auto Trait Implementations

impl<T> !RefUnwindSafe for ConstraintSystem<T>

impl<T> !Send for ConstraintSystem<T>

impl<T> !Sync for ConstraintSystem<T>

impl<T> Unpin for ConstraintSystem<T>

impl<T> !UnwindSafe for ConstraintSystem<T>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.