pub struct ManagedRef<T: ?Sized> { /* private fields */ }Expand description
Shared handle to a value owned by a Managed, the runtime &T.
Keeps its claim until dropped, and reports a dead owner by returning
None from ManagedRef::read.
Implementations§
Source§impl<T: ?Sized> ManagedRef<T>
impl<T: ?Sized> ManagedRef<T>
Sourcepub fn new(data: &T, lifetime: LifetimeRef) -> Self
pub fn new(data: &T, lifetime: LifetimeRef) -> Self
Pairs a reference with a shared borrow taken from its lifetime.
Sourcepub unsafe fn new_raw(data: *const T, lifetime: LifetimeRef) -> Option<Self>
pub unsafe fn new_raw(data: *const T, lifetime: LifetimeRef) -> Option<Self>
ManagedRef::new over a raw pointer. A null pointer yields None.
§Safety
data must stay valid for as long as lifetime says it does, and
lifetime must be the borrow state that guards it.
Sourcepub fn make(data: &T) -> (Self, Lifetime)
pub fn make(data: &T) -> (Self, Lifetime)
Builds a handle to a plain reference along with the lifetime that backs it.
The caller has to keep the returned Lifetime alive for at least as
long as the handle.
Sourcepub unsafe fn make_raw(data: *const T) -> Option<(Self, Lifetime)>
pub unsafe fn make_raw(data: *const T) -> Option<(Self, Lifetime)>
ManagedRef::make over a raw pointer.
§Safety
data must stay valid for as long as the returned handle lives.
Sourcepub fn into_inner(self) -> (LifetimeRef, *const T)
pub fn into_inner(self) -> (LifetimeRef, *const T)
Splits into the borrow token and the pointer.
Sourcepub fn into_dynamic(self) -> DynamicManagedRef
pub fn into_dynamic(self) -> DynamicManagedRef
Erases the type, keeping the same claim.
Sourcepub fn lifetime(&self) -> &LifetimeRef
pub fn lifetime(&self) -> &LifetimeRef
Returns the borrow token.
Sourcepub fn borrow(&self) -> Option<ManagedRef<T>>
pub fn borrow(&self) -> Option<ManagedRef<T>>
Takes another shared handle to the same value.
Sourcepub unsafe fn lazy_immutable(&self) -> ManagedLazy<T>
pub unsafe fn lazy_immutable(&self) -> ManagedLazy<T>
Turns this shared handle into an unclaimed one that can also write.
§Safety
The value was only borrowed immutably, so writing through the result is
only sound when nothing else holds a &T to it.
Sourcepub fn read(&self) -> Option<ValueReadAccess<'_, T>>
pub fn read(&self) -> Option<ValueReadAccess<'_, T>>
Guards the value for reading, or returns None when it is written or
the owner is gone.
Sourcepub unsafe fn map<U>(self, f: impl FnOnce(&T) -> &U) -> ManagedRef<U>
pub unsafe fn map<U>(self, f: impl FnOnce(&T) -> &U) -> ManagedRef<U>
Narrows this handle down to a part of the value, such as one field.
§Safety
f must return a reference into the same value, and the owner must
still be alive.