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 Boxand
Rc, methods on
Mooare all associated functions, which means you have to call them as, e.g.
Moo::make_mut(&value)instead of
value.make_mut(). This is so that there are no conflicts with the inner type
T`, which this type dereferences to.
Implementations§
Source§impl<T: Clone> Moo<T>
impl<T: Clone> Moo<T>
Sourcepub fn make_mut(this: &mut Moo<T>) -> &mut T
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.
Sourcepub fn unwrap_or_clone(this: Moo<T>) -> T
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<To, U> Biplate<To> for Moo<U>where
To: Uniplate,
U: Uniplate + Biplate<To>,
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>) -> Self>)
fn biplate(&self) -> (Tree<To>, Box<dyn Fn(Tree<To>) -> Self>)
§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<'de, T: Deserialize<'de>> Deserialize<'de> for Moo<T>
impl<'de, T: Deserialize<'de>> Deserialize<'de> for Moo<T>
Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Source§impl From<Moo<Expression>> for Expression
impl From<Moo<Expression>> for Expression
Source§fn from(val: Moo<Expression>) -> Self
fn from(val: Moo<Expression>) -> Self
Source§impl<T> Uniplate for Moo<T>where
T: Uniplate,
impl<T> Uniplate for Moo<T>where
T: Uniplate,
Source§fn uniplate(&self) -> (Tree<Self>, Box<dyn Fn(Tree<Self>) -> Self>)
fn uniplate(&self) -> (Tree<Self>, Box<dyn Fn(Tree<Self>) -> Self>)
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<T: Eq> Eq for Moo<T>
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>
impl<T> Sync for Moo<T>
impl<T> Unpin for Moo<T>
impl<T> UnwindSafe for Moo<T>where
T: RefUnwindSafe,
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> 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: 8 bytes