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<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<To, U> Biplate<To> for Moo<U>
where To: Uniplate, U: Uniplate + Biplate<To>,

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 · 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<'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<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 From<Moo<Expression>> for Expression

Source§

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

Converts to this type from the input type.
Source§

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

Source§

fn eq(&self, other: &Moo<T>) -> 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<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<'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<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<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 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<T> Eq for Moo<T>
where T: Eq,

Source§

impl<T> StructuralPartialEq for Moo<T>

Auto Trait Implementations§

§

impl<T> Freeze for Moo<T>

§

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

§

impl<T> Send for Moo<T>
where T: Sync + Send,

§

impl<T> Sync for Moo<T>
where T: Sync + Send,

§

impl<T> Unpin for Moo<T>

§

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

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<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 = 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
Source§

impl<T> DeserializeOwned for T
where 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: 8 bytes