pub struct VRcMapped<VTable: VTableMetaDropInPlace + 'static, MappedType: ?Sized> { /* private fields */ }
Expand description
VRcMapped allows bundling a VRc of a type along with a reference to an object that’s
reachable through the data the VRc owns and that satisfies the requirements of a Pin.
VRCMapped is constructed using VRc::map
and, like VRc, has a weak counterpart, VWeakMapped
.
Implementations§
source§impl<VTable: VTableMetaDropInPlace + 'static, MappedType: ?Sized> VRcMapped<VTable, MappedType>
impl<VTable: VTableMetaDropInPlace + 'static, MappedType: ?Sized> VRcMapped<VTable, MappedType>
sourcepub fn downgrade(this: &Self) -> VWeakMapped<VTable, MappedType>
pub fn downgrade(this: &Self) -> VWeakMapped<VTable, MappedType>
Returns a new VWeakMapped
that points to this instance and can be upgraded back to
a Self
as long as a VRc
/VMapped
exists.
sourcepub fn as_pin_ref(&self) -> Pin<&MappedType>
pub fn as_pin_ref(&self) -> Pin<&MappedType>
Create a Pinned reference to the mapped type.
This is safe because the map function returns a pinned reference.
sourcepub fn map<ReMappedType: ?Sized>(
this: Self,
map_fn: impl for<'r> FnOnce(Pin<&'r MappedType>) -> Pin<&'r ReMappedType>
) -> VRcMapped<VTable, ReMappedType>
pub fn map<ReMappedType: ?Sized>( this: Self, map_fn: impl for<'r> FnOnce(Pin<&'r MappedType>) -> Pin<&'r ReMappedType> ) -> VRcMapped<VTable, ReMappedType>
This function allows safely holding a reference to a field inside the VRcMapped
. 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
.
See also VRc::map