pub struct Marc<T: ?Sized + 'static> { /* private fields */ }Implementations§
Source§impl<T: ?Sized> Marc<T>
impl<T: ?Sized> Marc<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,
) -> Marc<U>
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.
Sourcepub fn try_map<U: ?Sized + 'static, F: FnOnce(&T) -> Option<&U>>(
self_: Self,
f: F,
) -> Result<Marc<U>, Marc<T>>
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.
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
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>
impl<T: Send + 'static> Marc<T>
Sourcepub fn from_arc(arc: Arc<T>) -> Self
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.
Sourcepub fn new(t: T) -> Self
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.