Marc

Struct Marc 

Source
pub struct Marc<T: ?Sized + 'static> { /* private fields */ }

Implementations§

Source§

impl<T: ?Sized> Marc<T>

Source

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

Source

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

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

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

Source§

impl<T: ?Sized> Marc<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, ) -> Marc<U>

Maps the value to a new Marc that refers to the data returned by the closure.

This only changes what data this particular Marc refers to. It does not introduce mutability - any Marc<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 Marc<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<Marc<U>, Marc<T>>

Attempts to map the Marc<T> , returning the new value on success and the old value otherwise.

This is simply a fallible version of Marc::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 Marc 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: Send + 'static> Marc<T>

Source

pub fn from_arc(arc: Arc<T>) -> Self

Creates a new Marc from an Arc that shares ownership of the Arc’s data.

Like Marc::new, this method requires T: Send + Sized + 'static. If you have an Arc<T> where T: ?Sized, then you can create an Marc<T> via Marc::from_borrow.

As long as the returned Marc is alive, the strong count of the Arc will be at least one. This is also the case if any Marc’s derived from the return value via Clone and Marc::map are alive. The strong count of the input Arc could be observed by another Arc 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 Marc that provides shared ownership of the T.

This method, like all ways of creating an Marc, has a Send + 'static bound that is not found on the corresponding Arc method. You can avoid the Send requirement by using Mrc::from_borrow to create an Mrc instead. The 'static requirement is fundamentally necessary for the soundness of this type and cannot be circumvented.

Trait Implementations§

Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

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

Source§

fn clone(&self) -> Self

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: ?Sized + Debug> Debug for Marc<T>

Source§

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

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

impl<T: Send + Default + 'static> Default for Marc<T>

Source§

fn default() -> Self

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

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

Source§

type Target = T

The resulting type after dereferencing.
Source§

fn deref(&self) -> &T

Dereferences the value.
Source§

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

Source§

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

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

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

Source§

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

Converts to this type from the input type.
Source§

impl<T: Send + 'static> From<Arc<T>> for Marc<T>

Source§

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

Converts to this type from the input type.
Source§

impl<T: Send + ?Sized + 'static> From<Box<T>> for Marc<T>

Source§

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

Converts to this type from the input type.
Source§

impl<'a, B> From<Cow<'a, B>> for Marc<B>
where B: ?Sized + ToOwned, &'a B: Into<Marc<B>>, <B as ToOwned>::Owned: Into<Marc<B>>,

Source§

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

Converts to this type from the input type.
Source§

impl From<String> for Marc<str>

Source§

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

Converts to this type from the input type.
Source§

impl<T: Send + 'static> From<T> for Marc<T>

Source§

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

Converts to this type from the input type.
Source§

impl<T: Send + 'static> From<Vec<T>> for Marc<[T]>

Source§

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

Converts to this type from the input type.
Source§

impl<T: Send + 'static> FromIterator<T> for Marc<[T]>

Source§

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

Creates a value from an iterator. Read more
Source§

impl<T: ?Sized + Hash> Hash for Marc<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 Marc<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) -> Self
where Self: Sized,

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

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

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

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

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

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

Source§

fn eq(&self, other: &Self) -> 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: ?Sized + PartialOrd<T>> PartialOrd for Marc<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

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

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

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

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

Source§

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

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

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

Source§

type Error = Marc<[T]>

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

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

Performs the conversion.
Source§

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

Source§

impl<T: Sync + ?Sized> Send for Marc<T>

Source§

impl<T: Sync + ?Sized> Sync for Marc<T>

Auto Trait Implementations§

§

impl<T> Freeze for Marc<T>
where T: ?Sized,

§

impl<T> !RefUnwindSafe for Marc<T>

§

impl<T> Unpin for Marc<T>
where T: ?Sized,

§

impl<T> !UnwindSafe for Marc<T>

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> From<!> for T

Source§

fn from(t: !) -> T

Converts to this type from the input type.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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