Skip to main content

RefPtr

Struct RefPtr 

Source
pub struct RefPtr<T>{ /* 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>

Source

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 ptr is valid and has a ref count already acquired.
  • ptr must have been allocated in such a way that calling T::recycle(ptr) is a correct way to deallocate the pointer.
Source

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.

Source

pub fn as_ptr(this: &Self) -> *const T

Returns the raw pointer to the object.

Source

pub fn ptr_eq(a: &Self, b: &Self) -> bool

Returns true if the two RefPtrs point to the same object.

Source

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.

Source

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.

Source

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.

Source

pub fn pin_init(init: impl PinInit<T, Infallible>) -> Result<Self, AllocError>

Use the given pin-initializer to pin-initialize a T inside of a new RefPtr.

Source

pub fn init(init: impl Init<T, Infallible>) -> Result<Self, AllocError>

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>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: HasRefCount + Recyclable> Deref for RefPtr<T>

Source§

type Target = T

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<T: HasRefCount + Recyclable> Drop for RefPtr<T>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl<T: HasRefCount + Recyclable> PartialEq for RefPtr<T>

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T: HasRefCount + Recyclable> PtrTraits for RefPtr<T>

Source§

const IS_MANAGED: bool = true

Whether the pointer type is managed (e.g., UniquePtr or RefPtr). Read more
Source§

type Target = T

The type pointed to by this pointer.
Source§

fn into_raw(self) -> *mut T

Consumes the pointer and returns a raw pointer to the target.
Source§

unsafe fn from_raw(raw: *mut T) -> Self

Creates an instance of Self from a raw pointer. Read more
Source§

fn get_ref(&self) -> &T

Returns a reference to the target.
Source§

impl<T: HasRefCount + Recyclable> Eq for RefPtr<T>

Source§

impl<T: HasRefCount + Recyclable> ManagedPtr for RefPtr<T>

Source§

impl<T: HasRefCount + Recyclable + Send + Sync> Send for RefPtr<T>

Source§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Init<T> for T

Source§

unsafe fn __init(self, slot: *mut T) -> Result<(), Infallible>

Initializes slot. Read more
Source§

fn chain<F>(self, f: F) -> ChainInit<Self, F, T, E>
where F: FnOnce(&mut T) -> Result<(), E>,

First initializes the value using self then calls the function f with the initialized value. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PinInit<T> for T

Source§

unsafe fn __pinned_init(self, slot: *mut T) -> Result<(), Infallible>

Initializes slot. Read more
Source§

fn pin_chain<F>(self, f: F) -> ChainPinInit<Self, F, T, E>
where F: FnOnce(Pin<&mut T>) -> Result<(), E>,

First initializes the value using self then calls the function f with the initialized value. Read more
Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.