pub struct DeclarationPtr { /* private fields */ }
Expand description
A shared pointer to a [Declaration
].
Two declaration pointers are equal if they point to the same underlying declaration.
§Id
The id of DeclarationPtr
obeys the following invariants:
-
Declaration pointers have the same id if they point to the same underlying declaration.
-
The id is immutable.
-
Changing the declaration pointed to by the declaration pointer does not change the id. This allows declarations to be updated by replacing them with a newer version of themselves.
Ord
, Hash
, and Eq
use id for comparisons.
§Serde
Declaration pointers can be serialised using the following serializers:
See their documentation for more information.
Implementations§
Source§impl DeclarationPtr
impl DeclarationPtr
Sourcepub fn new(name: Name, kind: DeclarationKind) -> DeclarationPtr
pub fn new(name: Name, kind: DeclarationKind) -> DeclarationPtr
Creates a new declaration.
§Examples
use conjure_cp_core::ast::{DeclarationPtr,Name,DeclarationKind,Domain,Range};
// letting MyDomain be int(1..5)
let declaration = DeclarationPtr::new(
Name::User("MyDomain".into()),
DeclarationKind::DomainLetting(Domain::Int(vec![
Range::Bounded(1,5)])));
Sourcepub fn new_var(name: Name, domain: Domain) -> DeclarationPtr
pub fn new_var(name: Name, domain: Domain) -> DeclarationPtr
Creates a new decision variable declaration with the decision category.
§Examples
use conjure_cp_core::ast::{DeclarationPtr,Name,DeclarationKind,Domain,Range};
// find x: int(1..5)
let declaration = DeclarationPtr::new_var(
Name::User("x".into()),
Domain::Int(vec![Range::Bounded(1,5)]));
Sourcepub fn new_var_quantified(name: Name, domain: Domain) -> DeclarationPtr
pub fn new_var_quantified(name: Name, domain: Domain) -> DeclarationPtr
Creates a new decision variable with the quantified category.
This is useful to represent a quantified / induction variable in a comprehension.
Sourcepub fn new_domain_letting(name: Name, domain: Domain) -> DeclarationPtr
pub fn new_domain_letting(name: Name, domain: Domain) -> DeclarationPtr
Creates a new domain letting declaration.
§Examples
use conjure_cp_core::ast::{DeclarationPtr,Name,DeclarationKind,Domain,Range};
// letting MyDomain be int(1..5)
let declaration = DeclarationPtr::new_domain_letting(
Name::User("MyDomain".into()),
Domain::Int(vec![Range::Bounded(1,5)]));
Sourcepub fn new_value_letting(name: Name, expression: Expression) -> DeclarationPtr
pub fn new_value_letting(name: Name, expression: Expression) -> DeclarationPtr
Creates a new value letting declaration.
§Examples
use conjure_cp_core::ast::{DeclarationPtr,Name,DeclarationKind,Domain,Range, Expression,
Literal,Atom,Moo};
use conjure_cp_core::{matrix_expr,metadata::Metadata};
// letting n be 10 + 10
let ten = Expression::Atomic(Metadata::new(),Atom::Literal(Literal::Int(10)));
let expression = Expression::Sum(Metadata::new(),Moo::new(matrix_expr![ten.clone(),ten]));
let declaration = DeclarationPtr::new_value_letting(
Name::User("n".into()),
expression);
Sourcepub fn new_given(name: Name, domain: Domain) -> DeclarationPtr
pub fn new_given(name: Name, domain: Domain) -> DeclarationPtr
Creates a new given declaration.
§Examples
use conjure_cp_core::ast::{DeclarationPtr,Name,DeclarationKind,Domain,Range};
// given n: int(1..5)
let declaration = DeclarationPtr::new_given(
Name::User("n".into()),
Domain::Int(vec![Range::Bounded(1,5)]));
Sourcepub fn new_record_field(entry: RecordEntry) -> DeclarationPtr
pub fn new_record_field(entry: RecordEntry) -> DeclarationPtr
Creates a new record field declaration.
§Examples
use conjure_cp_core::ast::{DeclarationPtr,Name,records::RecordEntry,Domain,Range};
// create declaration for field A in `find rec: record {A: int(0..1), B: int(0..2)}`
let field = RecordEntry {
name: Name::User("n".into()),
domain: Domain::Int(vec![Range::Bounded(1,5)])
};
let declaration = DeclarationPtr::new_record_field(field);
Sourcepub fn domain(&self) -> Option<Domain>
pub fn domain(&self) -> Option<Domain>
Gets the domain of the declaration, if it has one.
§Examples
use conjure_cp_core::ast::{DeclarationPtr,Name,Domain,Range};
// find a: int(1..5)
let declaration = DeclarationPtr::new_var(Name::User("a".into()),Domain::Int(vec![Range::Bounded(1,5)]));
assert!(declaration.domain().is_some_and(|x| x == Domain::Int(vec![Range::Bounded(1,5)])))
Sourcepub fn kind(&self) -> Ref<'_, DeclarationKind>
pub fn kind(&self) -> Ref<'_, DeclarationKind>
Gets the kind of the declaration.
§Examples
use conjure_cp_core::ast::{DeclarationPtr,DeclarationKind,Name,Domain,Range};
// find a: int(1..5)
let declaration = DeclarationPtr::new_var(Name::User("a".into()),Domain::Int(vec![Range::Bounded(1,5)]));
assert!(matches!(&declaration.kind() as &DeclarationKind, DeclarationKind::DecisionVariable(_)))
Sourcepub fn name(&self) -> Ref<'_, Name>
pub fn name(&self) -> Ref<'_, Name>
Gets the name of the declaration.
§Examples
use conjure_cp_core::ast::{DeclarationPtr,Name,Domain,Range};
// find a: int(1..5)
let declaration = DeclarationPtr::new_var(Name::User("a".into()),Domain::Int(vec![Range::Bounded(1,5)]));
assert_eq!(&declaration.name() as &Name, &Name::User("a".into()))
Sourcepub fn as_var(&self) -> Option<Ref<'_, DecisionVariable>>
pub fn as_var(&self) -> Option<Ref<'_, DecisionVariable>>
This declaration as a decision variable, if it is one.
Sourcepub fn as_var_mut(&mut self) -> Option<RefMut<'_, DecisionVariable>>
pub fn as_var_mut(&mut self) -> Option<RefMut<'_, DecisionVariable>>
This declaration as a mutable decision variable, if it is one.
Sourcepub fn as_domain_letting(&self) -> Option<Ref<'_, Domain>>
pub fn as_domain_letting(&self) -> Option<Ref<'_, Domain>>
This declaration as a domain letting, if it is one.
Sourcepub fn as_domain_letting_mut(&mut self) -> Option<RefMut<'_, Domain>>
pub fn as_domain_letting_mut(&mut self) -> Option<RefMut<'_, Domain>>
This declaration as a mutable domain letting, if it is one.
Sourcepub fn as_value_letting(&self) -> Option<Ref<'_, Expression>>
pub fn as_value_letting(&self) -> Option<Ref<'_, Expression>>
This declaration as a value letting, if it is one.
Sourcepub fn as_value_letting_mut(&mut self) -> Option<RefMut<'_, Expression>>
pub fn as_value_letting_mut(&mut self) -> Option<RefMut<'_, Expression>>
This declaration as a mutable value letting, if it is one.
Sourcepub fn replace_name(&mut self, name: Name) -> Name
pub fn replace_name(&mut self, name: Name) -> Name
Changes the name in this declaration, returning the old one.
§Examples
use conjure_cp_core::ast::{DeclarationPtr, Domain, Range, Name};
// find a: int(1..5)
let mut declaration = DeclarationPtr::new_var(Name::User("a".into()),Domain::Int(vec![Range::Bounded(1,5)]));
let old_name = declaration.replace_name(Name::User("b".into()));
assert_eq!(old_name,Name::User("a".into()));
assert_eq!(&declaration.name() as &Name,&Name::User("b".into()));
Sourcepub fn detach(self) -> DeclarationPtr
pub fn detach(self) -> DeclarationPtr
Creates a new declaration pointer with the same contents as self
that is not shared with
anyone else.
As the resulting pointer is unshared, it will have a new id.
§Examples
use conjure_cp_core::ast::{DeclarationPtr,Name,Domain,Range};
// find a: int(1..5)
let declaration = DeclarationPtr::new_var(Name::User("a".into()),Domain::Int(vec![Range::Bounded(1,5)]));
let mut declaration2 = declaration.clone();
declaration2.replace_name(Name::User("b".into()));
assert_eq!(&declaration.name() as &Name, &Name::User("b".into()));
assert_eq!(&declaration2.name() as &Name, &Name::User("b".into()));
declaration2 = declaration2.detach();
assert_eq!(&declaration2.name() as &Name, &Name::User("b".into()));
declaration2.replace_name(Name::User("c".into()));
assert_eq!(&declaration.name() as &Name, &Name::User("b".into()));
assert_eq!(&declaration2.name() as &Name, &Name::User("c".into()));
Trait Implementations§
Source§impl Biplate<DeclarationPtr> for Atom
impl Biplate<DeclarationPtr> for Atom
Source§fn biplate(
&self,
) -> (Tree<DeclarationPtr>, Box<dyn Fn(Tree<DeclarationPtr>) -> Atom>)
fn biplate( &self, ) -> (Tree<DeclarationPtr>, Box<dyn Fn(Tree<DeclarationPtr>) -> Atom>)
§fn with_children_bi(&self, children: VecDeque<To>) -> Self
fn with_children_bi(&self, children: VecDeque<To>) -> Self
§fn descend_bi(&self, op: &impl Fn(To) -> To) -> Self
fn descend_bi(&self, op: &impl 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: &impl Fn(To) -> To) -> Self
fn transform_bi(&self, op: &impl Fn(To) -> To) -> Self
§fn holes_bi(&self) -> impl Iterator<Item = (To, impl Fn(To))>
fn holes_bi(&self) -> impl Iterator<Item = (To, impl Fn(To))>
§fn contexts_bi(&self) -> impl Iterator<Item = (To, impl Fn(To))>
fn contexts_bi(&self) -> impl Iterator<Item = (To, impl Fn(To))>
Source§impl Biplate<DeclarationPtr> for DeclarationKind
impl Biplate<DeclarationPtr> for DeclarationKind
Source§fn biplate(
&self,
) -> (Tree<DeclarationPtr>, Box<dyn Fn(Tree<DeclarationPtr>) -> DeclarationKind>)
fn biplate( &self, ) -> (Tree<DeclarationPtr>, Box<dyn Fn(Tree<DeclarationPtr>) -> DeclarationKind>)
§fn with_children_bi(&self, children: VecDeque<To>) -> Self
fn with_children_bi(&self, children: VecDeque<To>) -> Self
§fn descend_bi(&self, op: &impl Fn(To) -> To) -> Self
fn descend_bi(&self, op: &impl 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: &impl Fn(To) -> To) -> Self
fn transform_bi(&self, op: &impl Fn(To) -> To) -> Self
§fn holes_bi(&self) -> impl Iterator<Item = (To, impl Fn(To))>
fn holes_bi(&self) -> impl Iterator<Item = (To, impl Fn(To))>
§fn contexts_bi(&self) -> impl Iterator<Item = (To, impl Fn(To))>
fn contexts_bi(&self) -> impl Iterator<Item = (To, impl Fn(To))>
Source§impl Biplate<DeclarationPtr> for Expression
impl Biplate<DeclarationPtr> for Expression
Source§fn biplate(
&self,
) -> (Tree<DeclarationPtr>, Box<dyn Fn(Tree<DeclarationPtr>) -> Expression>)
fn biplate( &self, ) -> (Tree<DeclarationPtr>, Box<dyn Fn(Tree<DeclarationPtr>) -> Expression>)
§fn with_children_bi(&self, children: VecDeque<To>) -> Self
fn with_children_bi(&self, children: VecDeque<To>) -> Self
§fn descend_bi(&self, op: &impl Fn(To) -> To) -> Self
fn descend_bi(&self, op: &impl 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: &impl Fn(To) -> To) -> Self
fn transform_bi(&self, op: &impl Fn(To) -> To) -> Self
§fn holes_bi(&self) -> impl Iterator<Item = (To, impl Fn(To))>
fn holes_bi(&self) -> impl Iterator<Item = (To, impl Fn(To))>
§fn contexts_bi(&self) -> impl Iterator<Item = (To, impl Fn(To))>
fn contexts_bi(&self) -> impl Iterator<Item = (To, impl Fn(To))>
Source§impl<To> Biplate<To> for DeclarationPtrwhere
Declaration: Biplate<To>,
To: Uniplate,
impl<To> Biplate<To> for DeclarationPtrwhere
Declaration: Biplate<To>,
To: Uniplate,
Source§fn biplate(&self) -> (Tree<To>, Box<dyn Fn(Tree<To>) -> DeclarationPtr>)
fn biplate(&self) -> (Tree<To>, Box<dyn Fn(Tree<To>) -> DeclarationPtr>)
§fn with_children_bi(&self, children: VecDeque<To>) -> Self
fn with_children_bi(&self, children: VecDeque<To>) -> Self
§fn descend_bi(&self, op: &impl Fn(To) -> To) -> Self
fn descend_bi(&self, op: &impl 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: &impl Fn(To) -> To) -> Self
fn transform_bi(&self, op: &impl Fn(To) -> To) -> Self
§fn holes_bi(&self) -> impl Iterator<Item = (To, impl Fn(To))>
fn holes_bi(&self) -> impl Iterator<Item = (To, impl Fn(To))>
§fn contexts_bi(&self) -> impl Iterator<Item = (To, impl Fn(To))>
fn contexts_bi(&self) -> impl Iterator<Item = (To, impl Fn(To))>
Source§impl CategoryOf for DeclarationPtr
impl CategoryOf for DeclarationPtr
Source§fn category_of(&self) -> Category
fn category_of(&self) -> Category
Category
of a term.Source§impl Clone for DeclarationPtr
impl Clone for DeclarationPtr
Source§fn clone(&self) -> DeclarationPtr
fn clone(&self) -> DeclarationPtr
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for DeclarationPtr
impl Debug for DeclarationPtr
Source§impl DefaultWithId for DeclarationPtr
impl DefaultWithId for DeclarationPtr
Source§fn default_with_id(id: u32) -> DeclarationPtr
fn default_with_id(id: u32) -> DeclarationPtr
T
, but with the given id.Source§impl<'de> DeserializeAs<'de, DeclarationPtr> for DeclarationPtrAsId
impl<'de> DeserializeAs<'de, DeclarationPtr> for DeclarationPtrAsId
Source§fn deserialize_as<D>(
deserializer: D,
) -> Result<DeclarationPtr, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
fn deserialize_as<D>(
deserializer: D,
) -> Result<DeclarationPtr, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
Source§impl<'de> DeserializeAs<'de, DeclarationPtr> for DeclarationPtrFull
impl<'de> DeserializeAs<'de, DeclarationPtr> for DeclarationPtrFull
Source§fn deserialize_as<D>(
deserializer: D,
) -> Result<DeclarationPtr, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
fn deserialize_as<D>(
deserializer: D,
) -> Result<DeclarationPtr, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
Source§impl Display for DeclarationPtr
impl Display for DeclarationPtr
Source§impl From<DeclarationPtr> for Atom
impl From<DeclarationPtr> for Atom
Source§fn from(value: DeclarationPtr) -> Atom
fn from(value: DeclarationPtr) -> Atom
Source§impl Hash for DeclarationPtr
impl Hash for DeclarationPtr
Source§impl Ord for DeclarationPtr
impl Ord for DeclarationPtr
Source§fn cmp(&self, other: &DeclarationPtr) -> Ordering
fn cmp(&self, other: &DeclarationPtr) -> Ordering
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialEq for DeclarationPtr
impl PartialEq for DeclarationPtr
Source§impl PartialOrd for DeclarationPtr
impl PartialOrd for DeclarationPtr
Source§impl SerializeAs<DeclarationPtr> for DeclarationPtrAsId
impl SerializeAs<DeclarationPtr> for DeclarationPtrAsId
Source§fn serialize_as<S>(
source: &DeclarationPtr,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
fn serialize_as<S>(
source: &DeclarationPtr,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
Source§impl SerializeAs<DeclarationPtr> for DeclarationPtrFull
impl SerializeAs<DeclarationPtr> for DeclarationPtrFull
Source§fn serialize_as<S>(
source: &DeclarationPtr,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
fn serialize_as<S>(
source: &DeclarationPtr,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
Source§impl Typeable for DeclarationPtr
impl Typeable for DeclarationPtr
fn return_type(&self) -> Option<ReturnType>
Source§impl Uniplate for DeclarationPtr
impl Uniplate for DeclarationPtr
Source§fn uniplate(
&self,
) -> (Tree<DeclarationPtr>, Box<dyn Fn(Tree<DeclarationPtr>) -> DeclarationPtr>)
fn uniplate( &self, ) -> (Tree<DeclarationPtr>, Box<dyn Fn(Tree<DeclarationPtr>) -> DeclarationPtr>)
Uniplate
. Read more§fn descend(&self, op: &impl Fn(Self) -> Self) -> Self
fn descend(&self, op: &impl 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: &impl Fn(Self) -> Self) -> Self
fn transform(&self, f: &impl Fn(Self) -> Self) -> Self
§fn rewrite(&self, f: &impl Fn(Self) -> Option<Self>) -> Self
fn rewrite(&self, f: &impl Fn(Self) -> Option<Self>) -> Self
§fn cata<T>(&self, op: &impl Fn(Self, VecDeque<T>) -> T) -> T
fn cata<T>(&self, op: &impl Fn(Self, VecDeque<T>) -> T) -> T
impl Eq for DeclarationPtr
Auto Trait Implementations§
impl Freeze for DeclarationPtr
impl !RefUnwindSafe for DeclarationPtr
impl !Send for DeclarationPtr
impl !Sync for DeclarationPtr
impl Unpin for DeclarationPtr
impl !UnwindSafe for DeclarationPtr
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<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 more§impl<T> Pointable for T
impl<T> Pointable for T
§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>
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: 8 bytes