Assignment

Struct Assignment 

Source
pub struct Assignment(/* private fields */);
Expand description

An assignment of a set of variables.

Inside the set of variables involved in the assignment, some may be unassigned. This is the reason why accessors to assigned value return an Option<bool>.

Implementations§

Source§

impl Assignment

Source

pub fn value_of<T>(&self, v: T) -> Option<bool>
where T: Into<Variable>,

Returns the value potentially assigned to the variable.

The result in an Option. In case the variable is not assigned, Option::None is returned. Else, Option::Some is returned and contains the assigned value.

In order to iterate over an assignment, prefer the iter function.

§Panic

If the provided variable does not belong to the underlying problem, this function panics.

§Example
let assignment = get_assignment(); // user defined function
let n_vars = get_n_vars(); // user defined function
for i in 1 ..= n_vars {
    match assignment.value_of(i) {
        Some(v) => println!("var {} is set to {}", i, v),
        None => println!("var {} is left unassigned", i),
    }
}
Source

pub fn iter(&self) -> impl Iterator<Item = (usize, Option<bool>)> + '_

Iterates over an assignment.

Yielded values are Option. In case the variable is not assigned, Option::None is returned. Else, Option::Some is returned and contains the assigned value.

§Example
let assignment = get_assignment(); // user defined function
assignment.iter().for_each(|opt_lit| {
    match opt_lit {
        (i, Some(v)) => println!("var {} is set to {}", i, v),
        (i, None) => println!("var {} is left unassigned", i),
    }
});

Trait Implementations§

Source§

impl Debug for Assignment

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for Assignment

Source§

fn eq(&self, other: &Assignment) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for Assignment

Source§

impl StructuralPartialEq for Assignment

Auto Trait Implementations§

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.