Struct vtable::VRc

source · []
#[repr(transparent)]
pub struct VRc<VTable: VTableMetaDropInPlace + 'static, X = Dyn> { /* private fields */ }
Expand description

A reference counted pointer to an object matching the virtual table T

Similar to alloc::rc::Rc where the VTable type parameter is a VTable struct annotated with #[vtable], and the X type parameter is the actual instance. When X is the Dyn type marker, this means that the X is not known and the only thing that can be done is to get a VRef<VTable> through the Self::borrow() function.

Other differences with the alloc::rc::Rc types are:

  • It does not allow to access mutable reference. (No get_mut or make_mut), meaning it is safe to get a Pin reference with borrow_pin.
  • It is safe to pass it across ffi boundaries.

Implementations

Create a new VRc from an instance of a type that can be associated with a VTable.

Will move the instance on the heap.

(the HasStaticVTable is implemented by the “MyTrait”VTable_static! macro generated by the #vtable macro)

Convert a VRc of a real instance to a VRc of a Dyn instance

This function allows safely holding a reference to a field inside the VRc. In order to accomplish that, you need to provide a mapping function map_fn in which you need to provide and return a pinned reference to the object you would like to map. The returned VRcMapped allows obtaining that pinned reference again using VRcMapped::as_pin_ref.

Create a Pinned reference to the inner.

This is safe because we don’t allow mutable reference to the inner

Gets a VRef pointing to this instance

Gets a Pin pointing to this instance

This is safe because there is no way to access a mutable reference to the pointee. (There is no get_mut or make_mut),

Construct a VWeak pointing to this instance.

Gets the number of strong (VRc) pointers to this allocation.

Returns true if the two VRc’s point to the same allocation

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

The resulting type after dereferencing.

Dereferences the value.

Executes the destructor for this type. Read more

Safety: The data VRc manages is held by VRcInner, and a clone of a VRc merely clones the pointer to the VRcInner.

Safety: The data VRc manages is held by VRcInner, which maintains its address when the VRc is moved.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The resulting type after obtaining ownership.

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

🔬 This is a nightly-only experimental API. (toowned_clone_into)

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

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.