Struct hotdrink_rs::model::Component[][src]

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

A collection of variables along with constraints that should be maintained between them. Variables can get new values, values can be retrieved from the component, and the constraints can be enforced. Subscribing to variables will send a notification when the new values are ready.

Implementations

impl<T> Component<T>[src]

pub fn new_empty(name: String) -> Self[src]

Constructs a new Constraint with the specified name.

pub fn subscribe<'s>(
    &mut self,
    variable: &'s str,
    callback: impl Fn(Event<'_, T, SolveError>) + Send + 'static
) -> Result<(), NoSuchVariable<'s>> where
    T: 'static, 
[src]

Add a callback to be called when a given variable is updated.

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

Unsubscribe from a variable to avoid receiving further events.

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

Give a variable a new value, and call its callback.

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

Returns the variable called variable, if one exists.

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

Returns the current activation of variable, if one exists.

pub fn name(&self) -> &str[src]

Returns a reference to the name of this component.

pub fn set_name<S: Into<String>>(&mut self, name: S)[src]

Sets the name of the component.

pub fn variable_names(&self) -> Vec<&str>[src]

Returns a Vec<&str> of names of variables in this component.

pub fn variables(&self) -> &[Variable<Activation<T>>][src]

Returns the variables of the component.

pub fn values(&self) -> Vec<&Activation<T>>[src]

Returns a Vec of the current values.

pub fn constraint<'a>(
    &self,
    name: &'a str
) -> Result<&Constraint<T>, NoSuchConstraint<'a>>
[src]

Returns a reference to the specified constraint.

pub fn constraint_mut<'a>(
    &mut self,
    name: &'a str
) -> Result<&mut Constraint<T>, NoSuchConstraint<'a>>
[src]

Returns a mutable reference to the specified constraint.

pub fn new_with_map(
    name: String,
    name_to_idx: HashMap<String, usize>,
    values: Vec<T>,
    constraints: Vec<Constraint<T>>
) -> Self
[src]

Constructs a new component from a precomputed map from variable names to indices.

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

Enforces all constraints in the component.

Returns PlanError if the system is overconstrained.

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

Enforces all constraints in the component concurrently.

Returns PlanError if the system is overconstrained.

pub fn pin<'s>(&mut self, variable: &'s str) -> Result<(), NoSuchVariable<'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 Component::unpin.

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

Unpins a variable.

This removes the stay constraint added by Component::pin.

pub fn is_modified(&self) -> bool[src]

Returns true if any variables have been updated since the last solve, meaning that any constraints may be broken.

pub fn ranking(&self) -> Vec<usize>[src]

Returns the current ranking of variables, based on when they were last updated.

pub fn to_dot_detailed(&self) -> Result<String, Error>[src]

Constructs a string-representation of a graph formatted in the dot language. This can be used for visualization of the constraint graph that the component represents. This function includes every method in a constraint.

pub fn to_dot_simple(&self) -> Result<String, Error>[src]

Constructs a string-representation of a graph formatted in the dot language. This can be used for visualization of the constraint graph that the component represents. This function only includes constraints, and not methods.

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

Jumps back to the previous set/update call.

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

Jumps forward to the next set/update call.

pub fn new_with_undo_limit(
    name: String,
    values: Vec<T>,
    constraints: Vec<Constraint<T>>,
    limit: usize
) -> Self
[src]

Constructs a new Component with the specified undo limit.

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

Sets the undo-limit on the values of the component.

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

Enables a specific constraint.

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

Disables a specific constraint.

Trait Implementations

impl<T> Clone for Component<T>[src]

impl<T> ComponentSpec for Component<T>[src]

type Value = Activation<T>

The variable type. It has more information than just the Value.

type Constraint = Constraint<T>

The type of the constraints of the component.

impl<T> Debug for Component<T> where
    T: Debug
[src]

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

impl<T> Index<&'_ str> for Component<T>[src]

type Output = Constraint<T>

The returned type after indexing.

fn index(&self, index: &str) -> &Self::Output[src]

Returns a reference to the constraint with the given name.

Panics

Panics if the constraint is not present in the Component.

impl<T> IndexMut<&'_ str> for Component<T>[src]

fn index_mut(&mut self, index: &str) -> &mut Self::Output[src]

Returns a mutable reference to the constraint with the given name.

Panics

Panics if the constraint is not present in the Component.

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

Auto Trait Implementations

impl<T> !RefUnwindSafe for Component<T>

impl<T> !Send for Component<T>

impl<T> !Sync for Component<T>

impl<T> Unpin for Component<T>

impl<T> !UnwindSafe for Component<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.