Struct hotdrink_rs::model::ConstraintSystem [−][src]
pub struct ConstraintSystem<T> { /* fields omitted */ }
A container for Component
s.
Implementations
impl<T> ConstraintSystem<T>
[src]
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]
&self,
name: &'s str
) -> Result<&Component<T>, NoSuchComponent<'s>>
Get a reference to the selected component.
pub fn component_mut<'s>(
&mut self,
name: &'s str
) -> Result<&mut Component<T>, NoSuchComponent<'s>>
[src]
&mut self,
name: &'s str
) -> Result<&mut Component<T>, NoSuchComponent<'s>>
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]
&mut self,
component: &'s str,
variable: &'s str,
value: impl Into<T>
) -> Result<(), NoSuchItem<'s>>
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]
&self,
component: &'a str,
variable: &'a str
) -> Result<&Variable<Activation<T>>, NoSuchItem<'a>>
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]
&self,
component: &'a str,
variable: &'a str
) -> Result<Activation<T>, NoSuchItem<'a>>
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]
T: Send + Sync + 'static + Debug,
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]
&mut self,
spawn: &mut impl ThreadPool
) -> Result<(), PlanError> where
T: Send + Sync + 'static + Debug,
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]
&mut self,
spawn: &mut impl ThreadPool
) -> Result<(), PlanError> where
T: Send + Sync + 'static + Debug,
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]
&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,
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]
&mut self,
component: &'a str,
variable: &'a str
) -> Result<(), NoSuchItem<'a>>
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]
&mut self,
component: &'s str,
variable: &'s str
) -> Result<(), NoSuchItem<'s>> where
T: 'static,
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]
&mut self,
component: &'s str,
variable: &'s str
) -> Result<(), NoSuchItem<'s>> where
T: 'static,
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]
&mut self,
component: &'a str,
variable: &'a str
) -> Result<(), NoSuchItem<'a>>
Enables the specified constraint.
pub fn disable_constraint<'a>(
&mut self,
component: &'a str,
variable: &'a str
) -> Result<(), NoSuchItem<'a>>
[src]
&mut self,
component: &'a str,
variable: &'a str
) -> Result<(), NoSuchItem<'a>>
Disabled the specified constraint.
Trait Implementations
impl<T: Clone> Clone for ConstraintSystem<T>
[src]
impl<T: Clone> Clone for ConstraintSystem<T>
[src]fn clone(&self) -> ConstraintSystem<T>
[src]
pub fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl<T: Debug> Debug for ConstraintSystem<T>
[src]
impl<T: Debug> Debug for ConstraintSystem<T>
[src]impl<T> Default for ConstraintSystem<T>
[src]
impl<T> Default for ConstraintSystem<T>
[src]impl<T: PartialEq> PartialEq<ConstraintSystem<T>> for ConstraintSystem<T>
[src]
impl<T: PartialEq> PartialEq<ConstraintSystem<T>> for ConstraintSystem<T>
[src]fn eq(&self, other: &ConstraintSystem<T>) -> bool
[src]
fn ne(&self, other: &ConstraintSystem<T>) -> bool
[src]
impl<T> StructuralPartialEq for ConstraintSystem<T>
[src]
impl<T> StructuralPartialEq for ConstraintSystem<T>
[src]Auto Trait Implementations
impl<T> !RefUnwindSafe for ConstraintSystem<T>
impl<T> !RefUnwindSafe for ConstraintSystem<T>
impl<T> !Send for ConstraintSystem<T>
impl<T> !Send for ConstraintSystem<T>
impl<T> !Sync for ConstraintSystem<T>
impl<T> !Sync for ConstraintSystem<T>
impl<T> Unpin for ConstraintSystem<T>
impl<T> Unpin for ConstraintSystem<T>
impl<T> !UnwindSafe for ConstraintSystem<T>
impl<T> !UnwindSafe for ConstraintSystem<T>