[][src]Enum ddo::Domain

pub enum Domain<'a> {
    Vector(Vec<isize>),
    Slice(&'a [isize]),
    BitSet(&'a BitSet),
    VarSet(&'a VarSet),
    Range(Range<isize>),
    RangeInclusive(RangeInclusive<isize>),
}

A domain is a set of values (isize) that may be assigned to some variable by a decision.

Important note

Domain implements the From trait for all of the usual collections. Therefore it is considered much better and cleaner to use .into() rather than manually specifying the variant of this enum.

Example

// This is considered much cleaner the alternative below
let clean : Domain<'_> = vec![1, 2, 4].into();
// This is more verbose and less clean. Still the two implementations
// are totally equivalent.
let ugly  : Domain<'_> = Domain::Vector(vec![1, 2, 4]);

Technical note

This enum covers the most common collections from which a domain may be built. These, however, should be considered transparent and only a way to iterate over those values. The technical reason for having this enum is the following: designing an api (trait) for the Problem that would not constraint how one can model a problem required the ability to return some polymorphic Domain. Ideally, this domain would have been an anonymous iterable data structure (IntoIter). But this was not possible as traits declaration forbid impl trait for return types. Hence, the only two remaining options were to either return a trait object (but that would've incurred a perf-penalty because of heap allocation), or to use a polymorphic algebraic data type. The second option was retained as it combines both efficiency and elegance (+ it is a fairly common approach to polymorphism in rust and c).

Variants

Vector(Vec<isize>)

When the domain consists of an owned vector (vec![])

When the domain consists of a slice (array or ref to vector)

BitSet(&'a BitSet)

When the domain is a compact bitset

VarSet(&'a VarSet)

When domain materialises a relation between variables (i.e. successor in a TSP), then the domain can be a varset. The possible values will be the ids of the variables present in the set.

Range(Range<isize>)

When the domain is an exclusive range (ie. 0..10)

RangeInclusive(RangeInclusive<isize>)

When the domain is an inclusive range (ie. 0..=10)

Trait Implementations

impl<'a> Clone for Domain<'a>[src]

impl<'a> From<&'a [isize]> for Domain<'a>[src]

Implements the conversion from a slice of integers to a domain

impl<'a> From<&'a BitSet> for Domain<'a>[src]

Implements the conversion from a bitset of integers to a domain

impl<'a> From<&'a VarSet> for Domain<'a>[src]

Implements the conversion from a varset to a domain

impl<'_> From<Range<isize>> for Domain<'_>[src]

Implements the conversion from a range of integers to a domain

impl<'_> From<RangeInclusive<isize>> for Domain<'_>[src]

Implements the conversion from an inclusive range of integers to a domain

impl<'_> From<Vec<isize, Global>> for Domain<'_>[src]

Implements the conversion from a vector of integers to a domain

impl<'a> IntoIterator for Domain<'a>[src]

As stated above, domains are considered only useful as a means to iterate over the set of values that may be affected to some given variable. Thus, Domain implements to IntoIterator trait which makes it suitable to use in loops (and gives anyone the ability to derive an iterator for the values of the domain).

type Item = isize

The type of the elements being iterated over.

type IntoIter = DomainIter<'a>

Which kind of iterator are we turning this into?

pub fn into_iter(self) -> Self::IntoIter[src]

Yields an iterator to go over the values of the domain.

Auto Trait Implementations

impl<'a> RefUnwindSafe for Domain<'a>

impl<'a> Send for Domain<'a>

impl<'a> Sync for Domain<'a>

impl<'a> Unpin for Domain<'a>

impl<'a> UnwindSafe for Domain<'a>

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.