pub enum Domain {
Bool,
Int(Vec<Range<i32>>),
Empty(ReturnType),
Reference(Name),
Set(SetAttr, Box<Domain>),
Matrix(Box<Domain>, Vec<Domain>),
Tuple(Vec<Domain>),
Record(Vec<RecordEntry>),
}
Variants§
Bool
Int(Vec<Range<i32>>)
An integer domain.
-
If multiple ranges are inside the domain, the values in the domain are the union of these ranges.
-
If no ranges are given, the int domain is considered unconstrained, and can take any integer value.
Empty(ReturnType)
An empty domain of the given type.
Reference(Name)
Set(SetAttr, Box<Domain>)
Matrix(Box<Domain>, Vec<Domain>)
A n-dimensional matrix with a value domain and n-index domains
Tuple(Vec<Domain>)
Record(Vec<RecordEntry>)
Implementations§
Source§impl Domain
impl Domain
Sourcepub fn contains(&self, lit: &Literal) -> Result<bool, DomainOpError>
pub fn contains(&self, lit: &Literal) -> Result<bool, DomainOpError>
Returns true if lit
is a member of the domain.
§Errors
DomainOpError::InputContainsReference
if the input domain is a reference or contains a reference, meaning that its members cannot be determined.
Sourcepub fn values_i32(&self) -> Result<Vec<i32>, DomainOpError>
pub fn values_i32(&self) -> Result<Vec<i32>, DomainOpError>
Returns a list of all possible values in the domain.
§Errors
DomainOpError::InputNotInteger
if the domain is not an integer domain.DomainOpError::InputUnbounded
if the domain is unbounded.
Sourcepub fn from_slice_i32(elements: &[i32]) -> Domain
pub fn from_slice_i32(elements: &[i32]) -> Domain
Creates an Domain::Int
containing the given integers.
Domain::from_set_i32
should be used instead where possible, as it is cheaper (it does
not need to sort its input).
§Examples
use conjure_core::ast::{Domain,Range};
let elements = vec![1,2,3,4,5];
let domain = Domain::from_slice_i32(&elements);
let Domain::Int(ranges) = domain else {
panic!("domain returned from from_slice_i32 should be a Domain::Int");
};
assert_eq!(ranges,vec![Range::Bounded(1,5)]);
use conjure_core::ast::{Domain,Range};
let elements = vec![1,2,4,5,7,8,9,10];
let domain = Domain::from_slice_i32(&elements);
let Domain::Int(ranges) = domain else {
panic!("domain returned from from_slice_i32 should be a Domain::Int");
};
assert_eq!(ranges,vec![Range::Bounded(1,2),Range::Bounded(4,5),Range::Bounded(7,10)]);
use conjure_core::ast::{Domain,Range,ReturnType};
let elements = vec![];
let domain = Domain::from_slice_i32(&elements);
assert!(matches!(domain,Domain::Empty(ReturnType::Int)))
Sourcepub fn from_set_i32(elements: &BTreeSet<i32>) -> Domain
pub fn from_set_i32(elements: &BTreeSet<i32>) -> Domain
Creates an Domain::Int
containing the given integers.
§Examples
use conjure_core::ast::{Domain,Range};
use std::collections::BTreeSet;
let elements = BTreeSet::from([1,2,3,4,5]);
let domain = Domain::from_set_i32(&elements);
let Domain::Int(ranges) = domain else {
panic!("domain returned from from_slice_i32 should be a Domain::Int");
};
assert_eq!(ranges,vec![Range::Bounded(1,5)]);
use conjure_core::ast::{Domain,Range};
use std::collections::BTreeSet;
let elements = BTreeSet::from([1,2,4,5,7,8,9,10]);
let domain = Domain::from_set_i32(&elements);
let Domain::Int(ranges) = domain else {
panic!("domain returned from from_set_i32 should be a Domain::Int");
};
assert_eq!(ranges,vec![Range::Bounded(1,2),Range::Bounded(4,5),Range::Bounded(7,10)]);
use conjure_core::ast::{Domain,Range,ReturnType};
use std::collections::BTreeSet;
let elements = BTreeSet::from([]);
let domain = Domain::from_set_i32(&elements);
assert!(matches!(domain,Domain::Empty(ReturnType::Int)))
Sourcepub fn values(&self) -> Result<Vec<Literal>, DomainOpError>
pub fn values(&self) -> Result<Vec<Literal>, DomainOpError>
Gets all the Literal
values inside this domain.
§Errors
DomainOpError::InputNotInteger
if the domain is not an integer domain.DomainOpError::InputContainsReference
if the domain is a reference or contains a reference, meaning that its values cannot be determined.
Sourcepub fn length(&self) -> Result<usize, DomainOpError>
pub fn length(&self) -> Result<usize, DomainOpError>
Gets the length of this domain.
§Errors
DomainOpError::InputUnbounded
if the input domain is of infinite size.DomainOpError::InputContainsReference
if the input domain is or contains a domain reference, meaning that its size cannot be determined.
Sourcepub fn apply_i32(
&self,
op: fn(i32, i32) -> Option<i32>,
other: &Domain,
) -> Result<Domain, DomainOpError>
pub fn apply_i32( &self, op: fn(i32, i32) -> Option<i32>, other: &Domain, ) -> Result<Domain, DomainOpError>
Returns the domain that is the result of applying a binary operation to two integer domains.
The given operator may return None
if the operation is not defined for its arguments.
Undefined values will not be included in the resulting domain.
§Errors
DomainOpError::InputUnbounded
if either of the input domains are unbounded.DomainOpError::InputNotInteger
if either of the input domains are not integers.
Sourcepub fn is_finite(&self) -> Result<bool, DomainOpError>
pub fn is_finite(&self) -> Result<bool, DomainOpError>
Returns true if the domain is finite.
§Errors
DomainOpError::InputContainsReference
if the input domain is or contains a domain reference, meaning that its size cannot be determined.
Sourcepub fn resolve(self, symbols: &SymbolTable) -> Domain
pub fn resolve(self, symbols: &SymbolTable) -> Domain
Resolves this domain to a ground domain, using the symbol table provided to resolve references.
A domain is ground iff it is not a domain reference, nor contains any domain references.
See also: SymbolTable::resolve_domain
.
§Panics
- If a reference domain in
self
does not exist in the given symbol table.
Sourcepub fn intersect(&self, other: &Domain) -> Result<Domain, DomainOpError>
pub fn intersect(&self, other: &Domain) -> Result<Domain, DomainOpError>
Calculates the intersection of two domains.
§Errors
DomainOpError::InputUnbounded
if either of the input domains are unbounded.DomainOpError::InputWrongType
if the input domains are different types, or are not integer or set domains.
Sourcepub fn union(&self, other: &Domain) -> Result<Domain, DomainOpError>
pub fn union(&self, other: &Domain) -> Result<Domain, DomainOpError>
Calculates the union of two domains.
§Errors
DomainOpError::InputUnbounded
if either of the input domains are unbounded.DomainOpError::InputWrongType
if the input domains are different types, or are not integer or set domains.
Trait Implementations§
Source§impl Biplate<Domain> for Domain
impl Biplate<Domain> for Domain
Source§fn biplate(&self) -> (Tree<Domain>, Box<dyn Fn(Tree<Domain>) -> Domain>)
fn biplate(&self) -> (Tree<Domain>, Box<dyn Fn(Tree<Domain>) -> Domain>)
§fn with_children_bi(&self, children: VecDeque<To>) -> Self
fn with_children_bi(&self, children: VecDeque<To>) -> Self
§fn descend_bi(&self, op: Arc<dyn Fn(To) -> To>) -> Self
fn descend_bi(&self, op: Arc<dyn Fn(To) -> To>) -> Self
Uniplate::descend
] Read more§fn universe_bi(&self) -> VecDeque<To>
fn universe_bi(&self) -> VecDeque<To>
§fn children_bi(&self) -> VecDeque<To>
fn children_bi(&self) -> VecDeque<To>
§fn transform_bi(&self, op: Arc<dyn Fn(To) -> To>) -> Self
fn transform_bi(&self, op: Arc<dyn Fn(To) -> To>) -> Self
Source§impl<'de> Deserialize<'de> for Domain
impl<'de> Deserialize<'de> for Domain
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<Domain, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<Domain, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Source§impl Serialize for Domain
impl Serialize for Domain
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
Source§impl Typeable for Domain
impl Typeable for Domain
fn return_type(&self) -> Option<ReturnType>
Source§impl Uniplate for Domain
impl Uniplate for Domain
Source§fn uniplate(&self) -> (Tree<Domain>, Box<dyn Fn(Tree<Domain>) -> Domain>)
fn uniplate(&self) -> (Tree<Domain>, Box<dyn Fn(Tree<Domain>) -> Domain>)
Uniplate
. Read more§fn descend(&self, op: Arc<dyn Fn(Self) -> Self>) -> Self
fn descend(&self, op: Arc<dyn Fn(Self) -> Self>) -> Self
§fn universe(&self) -> VecDeque<Self>
fn universe(&self) -> VecDeque<Self>
§fn with_children(&self, children: VecDeque<Self>) -> Self
fn with_children(&self, children: VecDeque<Self>) -> Self
§fn transform(&self, f: Arc<dyn Fn(Self) -> Self>) -> Self
fn transform(&self, f: Arc<dyn Fn(Self) -> Self>) -> Self
§fn rewrite(&self, f: Arc<dyn Fn(Self) -> Option<Self>>) -> Self
fn rewrite(&self, f: Arc<dyn Fn(Self) -> Option<Self>>) -> Self
§fn cata<T>(&self, op: Arc<dyn Fn(Self, VecDeque<T>) -> T>) -> T
fn cata<T>(&self, op: Arc<dyn Fn(Self, VecDeque<T>) -> T>) -> T
impl Eq for Domain
impl StructuralPartialEq for Domain
Auto Trait Implementations§
impl Freeze for Domain
impl RefUnwindSafe for Domain
impl Send for Domain
impl Sync for Domain
impl Unpin for Domain
impl UnwindSafe for Domain
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Serialize for T
impl<T> Serialize for T
fn erased_serialize(&self, serializer: &mut dyn Serializer) -> Result<(), Error>
fn do_erased_serialize( &self, serializer: &mut dyn Serializer, ) -> Result<(), ErrorImpl>
§impl<T> WithSubscriber for T
impl<T> WithSubscriber for T
§fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where
S: Into<Dispatch>,
§fn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Layout§
Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...)
attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.
Size: 40 bytes
Size for each variant:
Bool
: 0 bytesInt
: 28 bytesEmpty
: 20 bytesReference
: 36 bytesSet
: 20 bytesMatrix
: 36 bytesTuple
: 28 bytesRecord
: 28 bytes