Skip to main content

Domain

Trait Domain 

Source
pub trait Domain:
    Clone
    + PartialEq
    + Debug {
    type Value: Clone + PartialEq + Debug;

    // Required methods
    fn size(&self) -> usize;
    fn contains(&self, val: &Self::Value) -> bool;
    fn remove(&mut self, val: &Self::Value) -> bool;
    fn add(&mut self, val: &Self::Value);
    fn values(&self) -> Vec<Self::Value>;

    // Provided methods
    fn is_empty(&self) -> bool { ... }
    fn is_singleton(&self) -> bool { ... }
    fn singleton_value(&self) -> Option<Self::Value> { ... }
    fn iter(&self) -> impl Iterator<Item = Self::Value> { ... }
}
Expand description

A domain of possible values for a CSP variable.

The iteration primitive is iter(), not values(). Implementations should provide zero-allocation iterators where possible (e.g. BitsetDomain iterates bits from a u128 without heap allocation).

Required Associated Types§

Source

type Value: Clone + PartialEq + Debug

The type of individual values in this domain.

Required Methods§

Source

fn size(&self) -> usize

Number of values currently in the domain.

Source

fn contains(&self, val: &Self::Value) -> bool

Test membership.

Source

fn remove(&mut self, val: &Self::Value) -> bool

Remove a value from the domain. Returns true if the value was present.

Source

fn add(&mut self, val: &Self::Value)

Add a value back into the domain.

Source

fn values(&self) -> Vec<Self::Value>

Collect all current values into a Vec.

Provided Methods§

Source

fn is_empty(&self) -> bool

Whether the domain is empty (wipe-out).

Source

fn is_singleton(&self) -> bool

Whether the domain contains exactly one value.

Source

fn singleton_value(&self) -> Option<Self::Value>

If the domain is a singleton, return its sole value.

Source

fn iter(&self) -> impl Iterator<Item = Self::Value>

Iterate over current values without allocating.

Default delegates to values().into_iter(). Override for zero-alloc iteration (e.g. BitsetDomain yields bits from a u128 copy).

The returned iterator is owned — it does NOT borrow &self, so the domain can be mutated while iteration is in progress (the iterator holds a snapshot).

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§