DeclarationPtr

Struct DeclarationPtr 

Source
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:

  1. Declaration pointers have the same id if they point to the same underlying declaration.

  2. The id is immutable.

  3. 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

Source

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)])));
Source

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)]));
Source

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.

Source

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)]));
Source

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);
Source

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)]));
Source

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);
Source

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)])))
Source

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(_)))
Source

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()))
Source

pub fn as_var(&self) -> Option<Ref<'_, DecisionVariable>>

This declaration as a decision variable, if it is one.

Source

pub fn as_var_mut(&mut self) -> Option<RefMut<'_, DecisionVariable>>

This declaration as a mutable decision variable, if it is one.

Source

pub fn as_domain_letting(&self) -> Option<Ref<'_, Domain>>

This declaration as a domain letting, if it is one.

Source

pub fn as_domain_letting_mut(&mut self) -> Option<RefMut<'_, Domain>>

This declaration as a mutable domain letting, if it is one.

Source

pub fn as_value_letting(&self) -> Option<Ref<'_, Expression>>

This declaration as a value letting, if it is one.

Source

pub fn as_value_letting_mut(&mut self) -> Option<RefMut<'_, Expression>>

This declaration as a mutable value letting, if it is one.

Source

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()));
Source

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

Source§

fn biplate( &self, ) -> (Tree<DeclarationPtr>, Box<dyn Fn(Tree<DeclarationPtr>) -> Atom>)

Definition of a Biplate. Read more
§

fn with_children_bi(&self, children: VecDeque<To>) -> Self

Reconstructs the node with the given children. Read more
§

fn descend_bi(&self, op: &impl Fn(To) -> To) -> Self

Biplate variant of [Uniplate::descend] Read more
§

fn universe_bi(&self) -> VecDeque<To>

Gets all children of a node, including itself and all children. Read more
§

fn children_bi(&self) -> VecDeque<To>

Returns the children of a type. If to == from then it returns the original element (in contrast to children). Read more
§

fn transform_bi(&self, op: &impl Fn(To) -> To) -> Self

Applies the given function to all nodes bottom up. Read more
§

fn holes_bi(&self) -> impl Iterator<Item = (To, impl Fn(To))>

Returns an iterator over all direct children of the input, paired with a function that “fills the hole” where the child was with a new value. Read more
§

fn contexts_bi(&self) -> impl Iterator<Item = (To, impl Fn(To))>

Returns an iterator over the universe of the input, paired with a function that “fills the hole” where the child was with a new value. Read more
Source§

impl Biplate<DeclarationPtr> for DeclarationKind

Source§

fn biplate( &self, ) -> (Tree<DeclarationPtr>, Box<dyn Fn(Tree<DeclarationPtr>) -> DeclarationKind>)

Definition of a Biplate. Read more
§

fn with_children_bi(&self, children: VecDeque<To>) -> Self

Reconstructs the node with the given children. Read more
§

fn descend_bi(&self, op: &impl Fn(To) -> To) -> Self

Biplate variant of [Uniplate::descend] Read more
§

fn universe_bi(&self) -> VecDeque<To>

Gets all children of a node, including itself and all children. Read more
§

fn children_bi(&self) -> VecDeque<To>

Returns the children of a type. If to == from then it returns the original element (in contrast to children). Read more
§

fn transform_bi(&self, op: &impl Fn(To) -> To) -> Self

Applies the given function to all nodes bottom up. Read more
§

fn holes_bi(&self) -> impl Iterator<Item = (To, impl Fn(To))>

Returns an iterator over all direct children of the input, paired with a function that “fills the hole” where the child was with a new value. Read more
§

fn contexts_bi(&self) -> impl Iterator<Item = (To, impl Fn(To))>

Returns an iterator over the universe of the input, paired with a function that “fills the hole” where the child was with a new value. Read more
Source§

impl Biplate<DeclarationPtr> for Expression

Source§

fn biplate( &self, ) -> (Tree<DeclarationPtr>, Box<dyn Fn(Tree<DeclarationPtr>) -> Expression>)

Definition of a Biplate. Read more
§

fn with_children_bi(&self, children: VecDeque<To>) -> Self

Reconstructs the node with the given children. Read more
§

fn descend_bi(&self, op: &impl Fn(To) -> To) -> Self

Biplate variant of [Uniplate::descend] Read more
§

fn universe_bi(&self) -> VecDeque<To>

Gets all children of a node, including itself and all children. Read more
§

fn children_bi(&self) -> VecDeque<To>

Returns the children of a type. If to == from then it returns the original element (in contrast to children). Read more
§

fn transform_bi(&self, op: &impl Fn(To) -> To) -> Self

Applies the given function to all nodes bottom up. Read more
§

fn holes_bi(&self) -> impl Iterator<Item = (To, impl Fn(To))>

Returns an iterator over all direct children of the input, paired with a function that “fills the hole” where the child was with a new value. Read more
§

fn contexts_bi(&self) -> impl Iterator<Item = (To, impl Fn(To))>

Returns an iterator over the universe of the input, paired with a function that “fills the hole” where the child was with a new value. Read more
Source§

impl<To> Biplate<To> for DeclarationPtr
where Declaration: Biplate<To>, To: Uniplate,

Source§

fn biplate(&self) -> (Tree<To>, Box<dyn Fn(Tree<To>) -> DeclarationPtr>)

Definition of a Biplate. Read more
§

fn with_children_bi(&self, children: VecDeque<To>) -> Self

Reconstructs the node with the given children. Read more
§

fn descend_bi(&self, op: &impl Fn(To) -> To) -> Self

Biplate variant of [Uniplate::descend] Read more
§

fn universe_bi(&self) -> VecDeque<To>

Gets all children of a node, including itself and all children. Read more
§

fn children_bi(&self) -> VecDeque<To>

Returns the children of a type. If to == from then it returns the original element (in contrast to children). Read more
§

fn transform_bi(&self, op: &impl Fn(To) -> To) -> Self

Applies the given function to all nodes bottom up. Read more
§

fn holes_bi(&self) -> impl Iterator<Item = (To, impl Fn(To))>

Returns an iterator over all direct children of the input, paired with a function that “fills the hole” where the child was with a new value. Read more
§

fn contexts_bi(&self) -> impl Iterator<Item = (To, impl Fn(To))>

Returns an iterator over the universe of the input, paired with a function that “fills the hole” where the child was with a new value. Read more
Source§

impl CategoryOf for DeclarationPtr

Source§

fn category_of(&self) -> Category

Gets the Category of a term.
Source§

impl Clone for DeclarationPtr

Source§

fn clone(&self) -> DeclarationPtr

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for DeclarationPtr

Source§

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

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

impl DefaultWithId for DeclarationPtr

Source§

fn default_with_id(id: u32) -> DeclarationPtr

Creates a new default value of type T, but with the given id.
Source§

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>,

Deserialize this value from the given Serde deserializer.
Source§

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>,

Deserialize this value from the given Serde deserializer.
Source§

impl Display for DeclarationPtr

Source§

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

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

impl From<DeclarationPtr> for Atom

Source§

fn from(value: DeclarationPtr) -> Atom

Converts to this type from the input type.
Source§

impl HasId for DeclarationPtr

Source§

fn id(&self) -> u32

The id of this object. Read more
Source§

impl Hash for DeclarationPtr

Source§

fn hash<H>(&self, state: &mut H)
where H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Ord for DeclarationPtr

Source§

fn cmp(&self, other: &DeclarationPtr) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for DeclarationPtr

Source§

fn eq(&self, other: &DeclarationPtr) -> 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 PartialOrd for DeclarationPtr

Source§

fn partial_cmp(&self, other: &DeclarationPtr) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

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,

Serialize this value into the given Serde serializer.
Source§

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,

Serialize this value into the given Serde serializer.
Source§

impl Typeable for DeclarationPtr

Source§

impl Uniplate for DeclarationPtr

Source§

fn uniplate( &self, ) -> (Tree<DeclarationPtr>, Box<dyn Fn(Tree<DeclarationPtr>) -> DeclarationPtr>)

Definition of a Uniplate. Read more
§

fn descend(&self, op: &impl Fn(Self) -> Self) -> Self

Applies a function to all direct children of this Read more
§

fn universe(&self) -> VecDeque<Self>

Gets all children of a node, including itself and all children. Read more
§

fn children(&self) -> VecDeque<Self>

Gets the direct children (maximal substructures) of a node.
§

fn with_children(&self, children: VecDeque<Self>) -> Self

Reconstructs the node with the given children. Read more
§

fn transform(&self, f: &impl Fn(Self) -> Self) -> Self

Applies the given function to all nodes bottom up.
§

fn rewrite(&self, f: &impl Fn(Self) -> Option<Self>) -> Self

Rewrites by applying a rule everywhere it can.
§

fn cata<T>(&self, op: &impl Fn(Self, VecDeque<T>) -> T) -> T

Performs a fold-like computation on each value. Read more
§

fn holes(&self) -> impl Iterator<Item = (Self, impl Fn(Self))>

Returns an iterator over all direct children of the input, paired with a function that “fills the hole” where the child was with a new value.
§

fn contexts(&self) -> impl Iterator<Item = (Self, impl Fn(Self))>

Returns an iterator over the universe of the input, paired with a function that “fills the hole” where the child was with a new value. Read more
Source§

impl Eq for DeclarationPtr

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more

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