pub struct Ref<T: ?Sized> { /* private fields */ }
Expand description
A reference-counted pointer to an instance of T
.
The reference count is incremented when new instances of Ref
are created, and decremented
when they are dropped. When the count reaches zero, the underlying T
is also dropped.
Invariants
The reference count on an instance of Ref
is always non-zero.
The object pointed to by Ref
is always pinned.
Implementations
sourceimpl<T> Ref<T>
impl<T> Ref<T>
sourcepub fn into_usize(obj: Self) -> usize
pub fn into_usize(obj: Self) -> usize
Deconstructs a Ref
object into a usize
.
It can be reconstructed once via Ref::from_usize
.
sourcepub unsafe fn borrow_usize<'a>(encoded: usize) -> RefBorrow<'a, T>
pub unsafe fn borrow_usize<'a>(encoded: usize) -> RefBorrow<'a, T>
Borrows a Ref
instance previously deconstructed via Ref::into_usize
.
Safety
encoded
must have been returned by a previous call to Ref::into_usize
. Additionally,
Ref::from_usize
can only be called after all instances of RefBorrow
have been
dropped.
sourcepub unsafe fn from_usize(encoded: usize) -> Self
pub unsafe fn from_usize(encoded: usize) -> Self
Recreates a Ref
instance previously deconstructed via Ref::into_usize
.
Safety
encoded
must have been returned by a previous call to Ref::into_usize
. Additionally,
it can only be called once for each previous call to Ref::into_usize
.
sourceimpl<T: ?Sized> Ref<T>
impl<T: ?Sized> Ref<T>
sourcepub fn ptr_eq(a: &Self, b: &Self) -> bool
pub fn ptr_eq(a: &Self, b: &Self) -> bool
Determines if two reference-counted pointers point to the same underlying instance of T
.
sourcepub fn into_raw(obj: Self) -> *const T
pub fn into_raw(obj: Self) -> *const T
Deconstructs a Ref
object into a raw pointer.
It can be reconstructed once via Ref::from_raw
.
sourcepub unsafe fn from_raw(ptr: *const T) -> Self
pub unsafe fn from_raw(ptr: *const T) -> Self
Recreates a Ref
instance previously deconstructed via Ref::into_raw
.
This code relies on the repr(C)
layout of structs as described in
https://doc.rust-lang.org/reference/type-layout.html#reprc-structs.
Safety
ptr
must have been returned by a previous call to Ref::into_raw
. Additionally, it
can only be called once for each previous call to Ref::into_raw
.
Trait Implementations
sourceimpl<T: DeviceRemoval> DeviceRemoval for Ref<T>
impl<T: DeviceRemoval> DeviceRemoval for Ref<T>
sourcefn device_remove(&self)
fn device_remove(&self)
Cleans resources up when the device is removed. Read more
sourceimpl<T: 'static> PointerWrapper for Ref<T>
impl<T: 'static> PointerWrapper for Ref<T>
type Borrowed<'a> = RefBorrow<'a, T>
type Borrowed<'a> = RefBorrow<'a, T>
Type of values borrowed between calls to PointerWrapper::into_pointer
and
PointerWrapper::from_pointer
. Read more
sourcefn into_pointer(self) -> *const c_void
fn into_pointer(self) -> *const c_void
Returns the raw pointer.
sourceunsafe fn borrow<'a>(ptr: *const c_void) -> RefBorrow<'a, T>
unsafe fn borrow<'a>(ptr: *const c_void) -> RefBorrow<'a, T>
Returns a borrowed value. Read more
sourceunsafe fn from_pointer(ptr: *const c_void) -> Self
unsafe fn from_pointer(ptr: *const c_void) -> Self
Returns the instance back from the raw pointer. Read more
sourceunsafe fn borrow_mut<T: PointerWrapper>(
ptr: *const c_void
) -> ScopeGuard<T, fn(_: T)>
unsafe fn borrow_mut<T: PointerWrapper>(
ptr: *const c_void
) -> ScopeGuard<T, fn(_: T)>
Returns a mutably borrowed value. Read more
sourceimpl<T: ?Sized> Wrapper<T> for Ref<T>
impl<T: ?Sized> Wrapper<T> for Ref<T>
sourcefn into_pointer(self) -> NonNull<T>
fn into_pointer(self) -> NonNull<T>
Converts the wrapped object into a pointer that represents it.
sourceunsafe fn from_pointer(ptr: NonNull<T>) -> Self
unsafe fn from_pointer(ptr: NonNull<T>) -> Self
Converts the object back from the pointer representation. Read more
impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<Ref<U>> for Ref<T>
impl<T: ?Sized + Unsize<U>, U: ?Sized> DispatchFromDyn<Ref<U>> for Ref<T>
impl<T: ?Sized + Sync + Send> Send for Ref<T>
impl<T: ?Sized + Sync + Send> Sync for Ref<T>
Auto Trait Implementations
impl<T> !RefUnwindSafe for Ref<T>
impl<T: ?Sized> Unpin for Ref<T> where
T: Unpin,
impl<T> !UnwindSafe for Ref<T>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more