Skip to main content

Moo

Struct Moo 

Source
pub struct Moo<T> { /* private fields */ }
Expand description

A clone-on-write, reference counted pointer to an AST type.

Cloning values of this type will not clone the underlying value until it is modified, e.g., with Moo::make_mut.

Unlike Rc and Arc, trait implementations on this type do not need to preserve shared ownership - that is, two pointers that used to point to the same value may not do so after calling a trait method on them. In particular, calling Uniplate methods may cause a clone-on-write to occur.

Note: like BoxandRc, methods on Mooare all associated functions, which means you have to call them as, e.g.Moo::make_mut(&value)instead ofvalue.make_mut(). This is so that there are no conflicts with the inner type T`, which this type dereferences to.

Implementations§

Source§

impl Moo<Domain>

Source

pub fn resolve(&self) -> Result<Moo<GroundDomain>, DomainOpError>

Source

pub fn union(&self, other: &Moo<Domain>) -> Result<Moo<Domain>, DomainOpError>

Convenience method to take Domain::union of the Domains behind two DomainPtrs and wrap the result in a new DomainPtr.

Source

pub fn intersect( &self, other: &Moo<Domain>, ) -> Result<Moo<Domain>, DomainOpError>

Convenience method to take Domain::intersect of the Domains behind two DomainPtrs and wrap the result in a new DomainPtr.

Source§

impl<T> Moo<T>

Source

pub fn new(value: T) -> Moo<T>

Constructs a new Moo<T>.

Source§

impl<T> Moo<T>
where T: Clone,

Source

pub fn make_mut(this: &mut Moo<T>) -> &mut T

Makes a mutable reference into the given Moo.

If there are other Moo pointers to the same allocation, then make_mut will clone the inner value to a new allocation to ensure unique ownership. This is also referred to as clone-on-write.

Source

pub fn unwrap_or_clone(this: Moo<T>) -> T

If we have the only reference to T then unwrap it. Otherwise, clone T and return the clone.

Assuming moo_t is of type Moo<T>, this function is functionally equivalent to (*moo_t).clone(), but will avoid cloning the inner value where possible.

Trait Implementations§

Source§

impl<T> AsRef<T> for Moo<T>

Source§

fn as_ref(&self) -> &T

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl Biplate<Moo<Domain>> for Domain

Source§

fn biplate( &self, ) -> (Tree<Moo<Domain>>, Box<dyn Fn(Tree<Moo<Domain>>) -> Domain>)

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 children_bi_count(&self) -> usize

Number of children that would be returned by children_bi. Read more
§

fn try_replace_child_at_bi(&mut self, index: usize, child: To) -> bool

Replaces the indexth child of type To within self. 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<Moo<Domain>> for UnresolvedDomain

Source§

fn biplate( &self, ) -> (Tree<Moo<Domain>>, Box<dyn Fn(Tree<Moo<Domain>>) -> UnresolvedDomain>)

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 children_bi_count(&self) -> usize

Number of children that would be returned by children_bi. Read more
§

fn try_replace_child_at_bi(&mut self, index: usize, child: To) -> bool

Replaces the indexth child of type To within self. 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<Moo<Domain>> for Expression

Source§

fn biplate( &self, ) -> (Tree<Moo<Domain>>, Box<dyn Fn(Tree<Moo<Domain>>) -> 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 children_bi_count(&self) -> usize

Number of children that would be returned by children_bi. Read more
§

fn try_replace_child_at_bi(&mut self, index: usize, child: To) -> bool

Replaces the indexth child of type To within self. 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, U> Biplate<To> for Moo<U>
where To: Uniplate, U: Uniplate + Biplate<To>,

Source§

fn children_bi_count(&self) -> usize

Counts children through the pointer, without cloning the pointee.

The default implementation materialises children_bi, which goes via [Biplate::biplate] and therefore clones the whole inner value. Payload syncs call this once per tree level, so the default turns a single rewrite under a wide node (e.g. or over a large matrix) into O(n) work, and a full rewrite pass into O(n^2).

Source§

fn try_replace_child_at_bi(&mut self, index: usize, child: To) -> bool

Replaces a child through the pointer, cloning the pointee only when it is shared.

Mirrors [Biplate::children_bi_count] above: the default implementation clones the inner value twice (once to list children, once to rebuild) and structurally compares the old and new trees.

Source§

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

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

Source§

fn clone(&self) -> Moo<T>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<T> Debug for Moo<T>
where T: Debug,

Source§

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

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

impl<T> Deref for Moo<T>

Source§

type Target = T

The resulting type after dereferencing.
Source§

fn deref(&self) -> &<Moo<T> as Deref>::Target

Dereferences the value.
Source§

impl<T> DerefMut for Moo<T>
where T: Clone,

Source§

fn deref_mut(&mut self) -> &mut <Moo<T> as Deref>::Target

Mutably dereferences the value.
Source§

impl<'de, T> Deserialize<'de> for Moo<T>
where T: Deserialize<'de>,

Source§

fn deserialize<D>( deserializer: D, ) -> Result<Moo<T>, <D as Deserializer<'de>>::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<'de, T, As> DeserializeAs<'de, Moo<T>> for Moo<As>
where As: DeserializeAs<'de, T>,

Source§

fn deserialize_as<D>( deserializer: D, ) -> Result<Moo<T>, <D as Deserializer<'de>>::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer.
Source§

impl<T> Display for Moo<T>
where T: Display,

Source§

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

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

impl<T> Eq for Moo<T>
where T: Eq,

Source§

impl From<&Moo<GroundDomain>> for Moo<Domain>

Source§

fn from(value: &Moo<GroundDomain>) -> Moo<Domain>

Converts to this type from the input type.
Source§

impl From<&Moo<UnresolvedDomain>> for Moo<Domain>

Source§

fn from(value: &Moo<UnresolvedDomain>) -> Moo<Domain>

Converts to this type from the input type.
Source§

impl From<GroundDomain> for Moo<Domain>

Source§

fn from(value: GroundDomain) -> Moo<Domain>

Converts to this type from the input type.
Source§

impl From<Moo<Expression>> for Expression

Source§

fn from(val: Moo<Expression>) -> Expression

Converts to this type from the input type.
Source§

impl From<Moo<GroundDomain>> for Moo<Domain>

Source§

fn from(value: Moo<GroundDomain>) -> Moo<Domain>

Converts to this type from the input type.
Source§

impl From<Moo<UnresolvedDomain>> for Moo<Domain>

Source§

fn from(value: Moo<UnresolvedDomain>) -> Moo<Domain>

Converts to this type from the input type.
Source§

impl From<Reference> for Moo<Expression>

Source§

fn from(value: Reference) -> Moo<Expression>

Converts to this type from the input type.
Source§

impl<T> From<T> for Moo<T>

Source§

fn from(value: T) -> Moo<T>

Converts to this type from the input type.
Source§

impl From<UnresolvedDomain> for Moo<Domain>

Source§

fn from(value: UnresolvedDomain) -> Moo<Domain>

Converts to this type from the input type.
Source§

impl<A, B> FuncMap<A, B> for Moo<A>
where A: Clone,

Source§

type Output = Moo<B>

The output type of the functorial mapping Read more
Source§

fn func_map<F>(self, f: F) -> <Moo<A> as FuncMap<A, B>>::Output
where F: FnMut(A) -> B,

Applies the closure f to self in a functorial way
§

fn func_map_over<Q, F>(self, f: F) -> Self::Output
where F: FnMut(A) -> B, Q: FuncMarker<P>,

Applies the closure f to self in a functorial way, allowing explicit specification of the marker type P Read more
Source§

impl<T> Hash for Moo<T>
where T: Hash,

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<T> PartialEq for Moo<T>
where T: PartialEq,

Source§

fn eq(&self, other: &Moo<T>) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl<T> Quine for Moo<T>
where T: Quine,

Source§

impl<T> Serialize for Moo<T>
where T: Serialize,

Source§

fn serialize<S>( &self, serializer: S, ) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl<T, As> SerializeAs<Moo<T>> for Moo<As>
where As: SerializeAs<T>,

Source§

fn serialize_as<S>( source: &Moo<T>, serializer: S, ) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>
where S: Serializer,

Serialize this value into the given Serde serializer.
Source§

impl<T> StructuralPartialEq for Moo<T>
where T: PartialEq,

Source§

impl<'a> TryFrom<&'a Moo<Expression>> for &'a Atom

Source§

type Error = &'static str

The type returned in the event of a conversion error.
Source§

fn try_from( value: &'a Moo<Expression>, ) -> Result<&'a Atom, <&'a Atom as TryFrom<&'a Moo<Expression>>>::Error>

Performs the conversion.
Source§

impl TryFrom<&Moo<Atom>> for i32

Source§

type Error = &'static str

The type returned in the event of a conversion error.
Source§

fn try_from( value: &Moo<Atom>, ) -> Result<i32, <i32 as TryFrom<&Moo<Atom>>>::Error>

Performs the conversion.
Source§

impl TryFrom<&Moo<Literal>> for i32

Source§

type Error = &'static str

The type returned in the event of a conversion error.
Source§

fn try_from( value: &Moo<Literal>, ) -> Result<i32, <i32 as TryFrom<&Moo<Literal>>>::Error>

Performs the conversion.
Source§

impl TryFrom<Domain> for Moo<GroundDomain>

Source§

type Error = DomainOpError

The type returned in the event of a conversion error.
Source§

fn try_from( value: Domain, ) -> Result<Moo<GroundDomain>, <Moo<GroundDomain> as TryFrom<Domain>>::Error>

Performs the conversion.
Source§

impl TryFrom<IntVal> for Moo<Expression>

Source§

type Error = DomainOpError

The type returned in the event of a conversion error.
Source§

fn try_from( value: IntVal, ) -> Result<Moo<Expression>, <Moo<Expression> as TryFrom<IntVal>>::Error>

Performs the conversion.
Source§

impl TryFrom<Moo<Atom>> for i32

Source§

type Error = &'static str

The type returned in the event of a conversion error.
Source§

fn try_from(value: Moo<Atom>) -> Result<i32, <i32 as TryFrom<Moo<Atom>>>::Error>

Performs the conversion.
Source§

impl TryFrom<Moo<Domain>> for Moo<GroundDomain>

Source§

type Error = DomainOpError

The type returned in the event of a conversion error.
Source§

fn try_from( value: Moo<Domain>, ) -> Result<Moo<GroundDomain>, <Moo<GroundDomain> as TryFrom<Moo<Domain>>>::Error>

Performs the conversion.
Source§

impl TryFrom<Moo<Domain>> for GroundDomain

Source§

type Error = DomainOpError

The type returned in the event of a conversion error.
Source§

fn try_from( value: Moo<Domain>, ) -> Result<GroundDomain, <GroundDomain as TryFrom<Moo<Domain>>>::Error>

Performs the conversion.
Source§

impl TryFrom<Moo<Expression>> for Atom

Source§

type Error = &'static str

The type returned in the event of a conversion error.
Source§

fn try_from( value: Moo<Expression>, ) -> Result<Atom, <Atom as TryFrom<Moo<Expression>>>::Error>

Performs the conversion.
Source§

impl<A, B> TryFuncMap<A, B> for Moo<A>
where A: Clone,

Source§

type Output = Moo<B>

The output type of the functorial mapping Read more
Source§

fn try_func_map<E, F>( self, f: F, ) -> Result<<Moo<A> as TryFuncMap<A, B>>::Output, E>
where F: FnMut(A) -> Result<B, E>,

Tries to apply the closure f to self in a functorial way Read more
§

fn try_func_map_over<Q, E, F>(self, f: F) -> Result<Self::Output, E>
where F: FnMut(A) -> Result<B, E>, Q: FuncMarker<P>,

Tries to apply the closure f to self in a functorial way, allowing explicit specification of the marker type P Read more
Source§

impl<T> Uniplate for Moo<T>
where T: Uniplate,

Source§

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

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 try_replace_child_at(&mut self, index: usize, child: Self) -> bool

Replaces the indexth direct child of self. 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

Auto Trait Implementations§

§

impl<T> Freeze for Moo<T>
where Arc<T>: Freeze,

§

impl<T> RefUnwindSafe for Moo<T>
where Arc<T>: RefUnwindSafe,

§

impl<T> Send for Moo<T>
where Arc<T>: Send,

§

impl<T> Sync for Moo<T>
where Arc<T>: Sync,

§

impl<T> Unpin for Moo<T>
where Arc<T>: Unpin,

§

impl<T> UnsafeUnpin for Moo<T>
where Arc<T>: UnsafeUnpin,

§

impl<T> UnwindSafe for Moo<T>
where Arc<T>: UnwindSafe,

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
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

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

Source§

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

§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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.

§

impl<T, A> IntoAst<A> for T
where T: Into<A>, A: Ast,

§

fn into_ast(self, _a: &A) -> A

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
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 = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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