pub struct ARef<T: AlwaysRefCounted> { /* private fields */ }
Expand description
An owned reference to an always-reference-counted object.
The object’s reference count is automatically decremented when an instance of ARef
is
dropped. It is also automatically incremented when a new instance is created via
ARef::clone
.
Invariants
The pointer stored in ptr
is non-null and valid for the lifetime of the ARef
instance. In
particular, the ARef
instance owns an increment on the underlying object’s reference count.
Implementations§
source§impl<T: AlwaysRefCounted> ARef<T>
impl<T: AlwaysRefCounted> ARef<T>
sourcepub unsafe fn from_raw(ptr: NonNull<T>) -> Self
pub unsafe fn from_raw(ptr: NonNull<T>) -> Self
Creates a new instance of ARef
.
It takes over an increment of the reference count on the underlying object.
Safety
Callers must ensure that the reference count was incremented at least once, and that they
are properly relinquishing one increment. That is, if there is only one increment, callers
must not use the underlying object anymore – it is only safe to do so via the newly
created ARef
.