[][src]Struct vtable::VRc

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

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

Similar to std::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 std::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 accross ffi boundaries.


impl<VTable: VTableMetaDropInPlace, X: HasStaticVTable<VTable>> VRc<VTable, X>[src]

pub fn new(data: X) -> Self[src]

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)

pub fn into_dyn(this: Self) -> VRc<VTable, Dyn> where
    Self: 'static, 

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

impl<VTable: VTableMetaDropInPlace, X> VRc<VTable, X>[src]

pub fn as_pin_ref(&self) -> Pin<&X>[src]

Create a Pinned reference to the inner.

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

pub fn borrow(this: &Self) -> VRef<'_, VTable>[src]

Gets a VRef pointing to this instance

pub fn borrow_pin<'b>(this: &'b Self) -> Pin<VRef<'b, VTable>>[src]

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),

pub fn downgrade(this: &Self) -> VWeak<VTable, X>[src]

Construct a VWeak pointing to this instance.

pub fn strong_count(this: &Self) -> usize[src]

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

pub fn ptr_eq(this: &Self, other: &Self) -> bool[src]

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

Trait Implementations

impl<VTable: VTableMetaDropInPlace + 'static, X> Clone for VRc<VTable, X>[src]

impl<VTable: VTableMetaDropInPlace, X> Deref for VRc<VTable, X>[src]

type Target = X

The resulting type after dereferencing.

impl<VTable: VTableMetaDropInPlace + 'static, X> Drop for VRc<VTable, X>[src]

Auto Trait Implementations

impl<VTable, X = Dyn> !RefUnwindSafe for VRc<VTable, X>

impl<VTable, X = Dyn> !Send for VRc<VTable, X>

impl<VTable, X = Dyn> !Sync for VRc<VTable, X>

impl<VTable, X> Unpin for VRc<VTable, X>

impl<VTable, X = Dyn> !UnwindSafe for VRc<VTable, X>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized

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

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

impl<T> From<T> for T[src]

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

impl<T> ToOwned for T where
    T: Clone

type Owned = T

The resulting type after obtaining ownership.

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

type Error = Infallible

The type returned in the event of a conversion error.

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

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

The type returned in the event of a conversion error.