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
ormake_mut
), meaning it is safe to get a Pin reference withborrow_pin
. - It is safe to pass it across ffi boundaries.
Implementations§
source§impl<VTable: VTableMetaDropInPlace, X: HasStaticVTable<VTable>> VRc<VTable, X>
impl<VTable: VTableMetaDropInPlace, X: HasStaticVTable<VTable>> VRc<VTable, X>
source§impl<VTable: VTableMetaDropInPlace + 'static, X: HasStaticVTable<VTable> + 'static> VRc<VTable, X>
impl<VTable: VTableMetaDropInPlace + 'static, X: HasStaticVTable<VTable> + 'static> VRc<VTable, X>
sourcepub fn map<MappedType: ?Sized>(
this: Self,
map_fn: impl for<'r> FnOnce(Pin<&'r X>) -> Pin<&'r MappedType>
) -> VRcMapped<VTable, MappedType>
pub fn map<MappedType: ?Sized>( this: Self, map_fn: impl for<'r> FnOnce(Pin<&'r X>) -> Pin<&'r MappedType> ) -> VRcMapped<VTable, MappedType>
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
.
source§impl<VTable: VTableMetaDropInPlace + 'static> VRc<VTable, Dyn>
impl<VTable: VTableMetaDropInPlace + 'static> VRc<VTable, Dyn>
sourcepub fn map_dyn<MappedType: ?Sized>(
this: Self,
map_fn: impl for<'r> FnOnce(Pin<VRef<'r, VTable>>) -> Pin<&'r MappedType>
) -> VRcMapped<VTable, MappedType>
pub fn map_dyn<MappedType: ?Sized>( this: Self, map_fn: impl for<'r> FnOnce(Pin<VRef<'r, VTable>>) -> Pin<&'r MappedType> ) -> VRcMapped<VTable, MappedType>
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
.
This works similar to VRc::map
except that it works on a type-erased VRc.
source§impl<VTable: VTableMetaDropInPlace, X> VRc<VTable, X>
impl<VTable: VTableMetaDropInPlace, X> VRc<VTable, X>
sourcepub fn as_pin_ref(&self) -> Pin<&X>
pub fn as_pin_ref(&self) -> Pin<&X>
Create a Pinned reference to the inner.
This is safe because we don’t allow mutable reference to the inner
sourcepub fn borrow_pin(this: &Self) -> Pin<VRef<'_, VTable>>
pub fn borrow_pin(this: &Self) -> Pin<VRef<'_, VTable>>
Gets a Pin<VRef>
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
),
sourcepub fn strong_count(this: &Self) -> usize
pub fn strong_count(this: &Self) -> usize
Gets the number of strong (VRc) pointers to this allocation.
Trait Implementations§
source§impl<VTable: VTableMetaDropInPlace + 'static, X> Clone for VRc<VTable, X>
impl<VTable: VTableMetaDropInPlace + 'static, X> Clone for VRc<VTable, X>
source§impl<VTable: VTableMetaDropInPlace + 'static, X> Debug for VRc<VTable, X>
impl<VTable: VTableMetaDropInPlace + 'static, X> Debug for VRc<VTable, X>
source§impl<VTable: VTableMetaDropInPlace, X> Deref for VRc<VTable, X>
impl<VTable: VTableMetaDropInPlace, X> Deref for VRc<VTable, X>
source§impl<VTable: VTableMetaDropInPlace + 'static, X> Drop for VRc<VTable, X>
impl<VTable: VTableMetaDropInPlace + 'static, X> Drop for VRc<VTable, X>
impl<VTable: VTableMetaDropInPlace + 'static, X> CloneStableDeref for VRc<VTable, X>
Safety: The data VRc manages is held by VRcInner
, and a clone of a VRc merely clones the pointer
to the VRcInner
.
impl<VTable: VTableMetaDropInPlace + 'static, X: Send + Sync> Send for VRc<VTable, X>
impl<VTable: VTableMetaDropInPlace + 'static, X> StableDeref for VRc<VTable, X>
Safety: The data VRc manages is held by VRcInner
, which maintains its address when the VRc
is moved.