Struct mappable_rc::Mrc
source · pub struct Mrc<T: ?Sized + 'static> { /* private fields */ }
Implementations§
source§impl<T: ?Sized> Mrc<T>
impl<T: ?Sized> Mrc<T>
sourcepub fn as_ptr(&self) -> *const T
pub fn as_ptr(&self) -> *const T
Returns a read-only pointer to the referred to data.
The pointer is valid for as long as this value is alive.
sourcepub fn map<U: ?Sized + 'static, F: FnOnce(&T) -> &U>(self_: Self, f: F) -> Mrc<U>
pub fn map<U: ?Sized + 'static, F: FnOnce(&T) -> &U>(self_: Self, f: F) -> Mrc<U>
Maps the value to a new
Mrc
that refers to the data returned by the closure.
This only changes what data this particular
Mrc
refers to. It does not introduce mutability - any
Mrc<T>
s
you’ve cloned from this one in the past still point to the same thing. Of course, if
you clone the value returned by this function, then the resulting
Mrc<U>
s
will also point to the mapped value.
This does not cause the T
to be dropped early. Even if the &U
refers to only a
part of the &T
, no part of the T
is dropped until all references to or into the
T
are gone, at which point the entire T
is dropped at once.
sourcepub fn try_map<U: ?Sized + 'static, F: FnOnce(&T) -> Option<&U>>(
self_: Self,
f: F
) -> Result<Mrc<U>, Mrc<T>>
pub fn try_map<U: ?Sized + 'static, F: FnOnce(&T) -> Option<&U>>( self_: Self, f: F ) -> Result<Mrc<U>, Mrc<T>>
Attempts to map the
Mrc<T>
, returning the new value on success and the old value otherwise.
This is simply a fallible version of
Mrc::map
, and generally has all the same properties.
sourcepub fn map_in_place<F: FnOnce(&T) -> &T>(self_: &mut Self, f: F)
pub fn map_in_place<F: FnOnce(&T) -> &T>(self_: &mut Self, f: F)
Maps the value that the
Mrc
refers to, without taking ownership.
This is equivalent to cloning, mapping, and then writing to self
, except that it
is slightly more efficient because it avoids the clone.
self
is left unchanged if f
panics.
source§impl<T: 'static> Mrc<T>
impl<T: 'static> Mrc<T>
sourcepub fn from_rc(rc: Rc<T>) -> Self
pub fn from_rc(rc: Rc<T>) -> Self
Creates a new Mrc
from an Rc
that shares ownership of the Rc
’s data.
Like Mrc::new
, this method requires T: Sized + 'static
. If you have an
Rc<T>
where T: ?Sized
, then you can create an Mrc<T>
via Mrc::from_borrow
.
As long as the returned Mrc
is alive, the strong count of the Rc
will be at least one.
This is also the case if any Mrc
’s derived from the return value via Clone
and
Mrc::map
are alive. The strong count of the input Rc
could be observed by another Rc
also sharing ownership of the data. It is not specified whether clones of the return value
will be reflected in that strong count.
This function is essentially free to call. After inlining, it will consist of one to two pointer copies.
sourcepub fn new(t: T) -> Self
pub fn new(t: T) -> Self
Creates a new Mrc
that provides shared ownership of the T
.
This method, like all ways of creating an Mrc
, has a 'static
bound that is not found on
the corresponding Rc
method. That requirement is fundamentally necessary for the soundness
of this type and cannot be circumvented.
Trait Implementations§
source§impl<'a, B> From<Cow<'a, B>> for Mrc<B>where
B: ?Sized + ToOwned,
&'a B: Into<Mrc<B>>,
<B as ToOwned>::Owned: Into<Mrc<B>>,
impl<'a, B> From<Cow<'a, B>> for Mrc<B>where B: ?Sized + ToOwned, &'a B: Into<Mrc<B>>, <B as ToOwned>::Owned: Into<Mrc<B>>,
source§impl<T: 'static> FromIterator<T> for Mrc<[T]>
impl<T: 'static> FromIterator<T> for Mrc<[T]>
source§impl<T: ?Sized + Ord> Ord for Mrc<T>
impl<T: ?Sized + Ord> Ord for Mrc<T>
source§impl<T: ?Sized + PartialEq<T>> PartialEq<Mrc<T>> for Mrc<T>
impl<T: ?Sized + PartialEq<T>> PartialEq<Mrc<T>> for Mrc<T>
source§impl<T: ?Sized + PartialOrd<T>> PartialOrd<Mrc<T>> for Mrc<T>
impl<T: ?Sized + PartialOrd<T>> PartialOrd<Mrc<T>> for Mrc<T>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read more