Struct mappable_rc::Mrc

source ·
pub struct Mrc<T: ?Sized + 'static> { /* private fields */ }

Implementations§

source§

impl<T: ?Sized> Mrc<T>

source

pub fn ptr_eq(this: &Self, other: &Self) -> bool

source

pub fn from_borrow<C>(c: C) -> Selfwhere C: Borrow<T> + 'static,

Creates a Mrc<T> from a value that borrows T.

This is just implemented as Mrc::map(Mrc::new(c), |c| c.borrow()).

source§

impl<T: ?Sized> Mrc<T>

source

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.

source

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.

source

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.

source

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>

source

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.

source

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<T: ?Sized> AsRef<T> for Mrc<T>

source§

fn as_ref(&self) -> &T

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

impl<T: ?Sized> Borrow<T> for Mrc<T>

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T: ?Sized> Clone for Mrc<T>

Creates a new Mrc<T> sharing ownership of the same data.

source§

fn clone(&self) -> Self

Returns a copy 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: ?Sized + Debug> Debug for Mrc<T>

source§

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

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

impl<T: Default + 'static> Default for Mrc<T>

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl<T: ?Sized> Deref for Mrc<T>

§

type Target = T

The resulting type after dereferencing.
source§

fn deref(&self) -> &T

Dereferences the value.
source§

impl<T: ?Sized + Display> Display for Mrc<T>

source§

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

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

impl<T: Clone + 'static> From<&[T]> for Mrc<[T]>

source§

fn from(r: &[T]) -> Self

Converts to this type from the input type.
source§

impl<T: ?Sized + 'static> From<Box<T, Global>> for Mrc<T>

source§

fn from(b: Box<T>) -> Mrc<T>

Converts to this type from the input type.
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>>,

source§

fn from(b: Cow<'a, B>) -> Mrc<B>

Converts to this type from the input type.
source§

impl<T: 'static> From<Rc<T>> for Mrc<T>

source§

fn from(a: Rc<T>) -> Self

Converts to this type from the input type.
source§

impl From<String> for Mrc<str>

source§

fn from(s: String) -> Mrc<str>

Converts to this type from the input type.
source§

impl<T: 'static> From<T> for Mrc<T>

source§

fn from(t: T) -> Mrc<T>

Converts to this type from the input type.
source§

impl<T: 'static> From<Vec<T, Global>> for Mrc<[T]>

source§

fn from(v: Vec<T>) -> Mrc<[T]>

Converts to this type from the input type.
source§

impl<T: 'static> FromIterator<T> for Mrc<[T]>

source§

fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Mrc<[T]>

Creates a value from an iterator. Read more
source§

impl<T: ?Sized + Hash> Hash for Mrc<T>

source§

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

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: ?Sized + Ord> Ord for Mrc<T>

source§

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

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

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

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

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

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

fn clamp(self, min: Self, max: Self) -> Selfwhere Self: Sized + PartialOrd<Self>,

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

impl<T: ?Sized + PartialEq<T>> PartialEq<Mrc<T>> for Mrc<T>

source§

fn eq(&self, other: &Self) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<T: ?Sized + PartialOrd<T>> PartialOrd<Mrc<T>> for Mrc<T>

source§

fn partial_cmp(&self, other: &Self) -> 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

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

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

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

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl<T: ?Sized> Pointer for Mrc<T>

source§

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

Formats the value using the given formatter.
source§

impl<T, const N: usize> TryFrom<Mrc<[T]>> for Mrc<[T; N]>

§

type Error = Mrc<[T]>

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

fn try_from(s: Mrc<[T]>) -> Result<Mrc<[T; N]>, Mrc<[T]>>

Performs the conversion.
source§

impl<T: ?Sized + Eq> Eq for Mrc<T>

Auto Trait Implementations§

§

impl<T> !RefUnwindSafe for Mrc<T>

§

impl<T> !Send for Mrc<T>

§

impl<T> !Sync for Mrc<T>

§

impl<T: ?Sized> Unpin for Mrc<T>

§

impl<T> !UnwindSafe for Mrc<T>

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<!> for T

const: unstable · source§

fn from(t: !) -> T

Converts to this type from the input type.
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · 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> ToOwned for Twhere T: Clone,

§

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 Twhere T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.