pub struct RefPtr<T>where
T: HasRefCount + Recyclable,{ /* private fields */ }Expand description
RefPtr<T> holds a reference to an intrusively-refcounted object of type
T that deletes the object when the refcount drops to 0.
T should be a struct that contains a fbl::RefCounted field and implements
HasRefCount and Destroy traits.
Implementations§
Source§impl<T: HasRefCount + Recyclable> RefPtr<T>
impl<T: HasRefCount + Recyclable> RefPtr<T>
Sourcepub unsafe fn from_raw(ptr: *const T) -> Self
pub unsafe fn from_raw(ptr: *const T) -> Self
Constructs a RefPtr from a raw pointer that has already been adopted.
§Safety
- The caller must ensure that
ptris valid and has a ref count already acquired. ptrmust have been allocated in such a way that callingT::recycle(ptr)is a correct way to deallocate the pointer.
Sourcepub unsafe fn try_new(value: T) -> Result<RefPtr<T>, AllocError>
pub unsafe fn try_new(value: T) -> Result<RefPtr<T>, AllocError>
Helper function that allocates a new instance of T using T::allocate and
returns a RefPtr wrapping it.
This is an internal helper function that should not be used directly.
Use the make_ref_counted!(...) macro instead of this function to properly
initialize the ref count.
§Safety
The caller must ensure that T has a RefCounted field that is not
already adopted.
Sourcepub fn ptr_eq(a: &Self, b: &Self) -> bool
pub fn ptr_eq(a: &Self, b: &Self) -> bool
Returns true if the two RefPtrs point to the same object.
Sourcepub fn into_raw(this: Self) -> *const T
pub fn into_raw(this: Self) -> *const T
Consume the RefPtr and return the raw pointer without modifying the ref count.
The caller is responsible for maintaining the reference count.
Sourcepub fn try_pin_init<E>(init: impl PinInit<T, E>) -> Result<Self, E>
pub fn try_pin_init<E>(init: impl PinInit<T, E>) -> Result<Self, E>
Use the given pin-initializer to pin-initialize a T inside of a new RefPtr.
Sourcepub fn try_init<E>(init: impl Init<T, E>) -> Result<Self, E>
pub fn try_init<E>(init: impl Init<T, E>) -> Result<Self, E>
Use the given initializer to in-place initialize a T inside of a new RefPtr.
Sourcepub fn pin_init(init: impl PinInit<T, Infallible>) -> Result<Self, AllocError>where
T: UninitRecyclable,
pub fn pin_init(init: impl PinInit<T, Infallible>) -> Result<Self, AllocError>where
T: UninitRecyclable,
Use the given pin-initializer to pin-initialize a T inside of a new RefPtr.
Sourcepub fn init(init: impl Init<T, Infallible>) -> Result<Self, AllocError>where
T: UninitRecyclable,
pub fn init(init: impl Init<T, Infallible>) -> Result<Self, AllocError>where
T: UninitRecyclable,
Use the given initializer to in-place initialize a T inside of a new RefPtr.
Trait Implementations§
Source§impl<T: HasRefCount + Recyclable> Clone for RefPtr<T>
impl<T: HasRefCount + Recyclable> Clone for RefPtr<T>
Source§impl<T: HasRefCount + Recyclable> Deref for RefPtr<T>
impl<T: HasRefCount + Recyclable> Deref for RefPtr<T>
Source§impl<T: HasRefCount + Recyclable> Drop for RefPtr<T>
impl<T: HasRefCount + Recyclable> Drop for RefPtr<T>
Source§impl<T: HasRefCount + Recyclable> PartialEq for RefPtr<T>
impl<T: HasRefCount + Recyclable> PartialEq for RefPtr<T>
Source§impl<T: HasRefCount + Recyclable> PtrTraits for RefPtr<T>
impl<T: HasRefCount + Recyclable> PtrTraits for RefPtr<T>
impl<T: HasRefCount + Recyclable> Eq for RefPtr<T>
impl<T: HasRefCount + Recyclable> ManagedPtr for RefPtr<T>
impl<T: HasRefCount + Recyclable + Send + Sync> Send for RefPtr<T>
impl<T: HasRefCount + Recyclable + Send + Sync> Sync for RefPtr<T>
Auto Trait Implementations§
impl<T> Freeze for RefPtr<T>
impl<T> RefUnwindSafe for RefPtr<T>where
T: RefUnwindSafe,
impl<T> Unpin for RefPtr<T>
impl<T> UnsafeUnpin for RefPtr<T>
impl<T> UnwindSafe for RefPtr<T>where
T: RefUnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> PinInit<T> for T
impl<T> PinInit<T> for T
Source§unsafe fn __pinned_init(self, slot: *mut T) -> Result<(), Infallible>
unsafe fn __pinned_init(self, slot: *mut T) -> Result<(), Infallible>
slot. Read more