pub struct DynamicManagedRef { /* private fields */ }Expand description
Shared handle to a value whose type is only known at runtime.
The ManagedRef counterpart for script values.
Implementations§
Source§impl DynamicManagedRef
impl DynamicManagedRef
Sourcepub fn new<T: ?Sized>(data: &T, lifetime: LifetimeRef) -> Self
pub fn new<T: ?Sized>(data: &T, lifetime: LifetimeRef) -> Self
Pairs a reference with a shared borrow taken from its lifetime.
Sourcepub unsafe fn new_raw(
type_hash: TypeHash,
lifetime: LifetimeRef,
data: *const u8,
) -> Option<Self>
pub unsafe fn new_raw( type_hash: TypeHash, lifetime: LifetimeRef, data: *const u8, ) -> Option<Self>
DynamicManagedRef::new for a type only known at runtime. A null
pointer yields None.
§Safety
data must point at a value of the type named by type_hash, and must
stay valid for as long as lifetime says it does.
Sourcepub fn make<T: ?Sized>(data: &T) -> (Self, Lifetime)
pub fn make<T: ?Sized>(data: &T) -> (Self, Lifetime)
Builds a handle to a plain reference along with the lifetime that backs it.
Sourcepub fn into_inner(self) -> (TypeHash, LifetimeRef, *const u8)
pub fn into_inner(self) -> (TypeHash, LifetimeRef, *const u8)
Splits into type, borrow token and pointer.
Sourcepub fn into_typed<T>(self) -> Result<ManagedRef<T>, Self>
pub fn into_typed<T>(self) -> Result<ManagedRef<T>, Self>
Recovers the typed handle, or gives self back on a type mismatch.
Sourcepub fn lifetime(&self) -> &LifetimeRef
pub fn lifetime(&self) -> &LifetimeRef
Returns the borrow token.
Sourcepub fn borrow(&self) -> Option<DynamicManagedRef>
pub fn borrow(&self) -> Option<DynamicManagedRef>
Takes another shared handle to the same value.
Sourcepub unsafe fn lazy_immutable(&self) -> DynamicManagedLazy
pub unsafe fn lazy_immutable(&self) -> DynamicManagedLazy
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 shared reference to it.
Sourcepub fn read<T>(&self) -> Option<ValueReadAccess<'_, T>>
pub fn read<T>(&self) -> Option<ValueReadAccess<'_, T>>
Guards the value for reading, or returns None on a type mismatch or
while it is written.