pub struct VRef<'a, T: ?Sized + VTableMeta> { /* private fields */ }Expand description
VRef<'a MyTraitVTable> can be thought as a &'a dyn MyTrait
It will dereference to a structure that has the same members as MyTrait.
Implementations§
Source§impl<'a, T: ?Sized + VTableMeta> VRef<'a, T>
impl<'a, T: ?Sized + VTableMeta> VRef<'a, T>
Sourcepub fn new<X: HasStaticVTable<T>>(value: &'a X) -> Self
pub fn new<X: HasStaticVTable<T>>(value: &'a X) -> Self
Create a new VRef from an reference of a type that can be associated with a VTable.
(the HasStaticVTable is implemented by the “MyTrait”VTable_static! macro generated by
the #vtable macro)
Sourcepub fn new_pin<X: HasStaticVTable<T>>(value: Pin<&'a X>) -> Pin<Self>
pub fn new_pin<X: HasStaticVTable<T>>(value: Pin<&'a X>) -> Pin<Self>
Create a new Pin<VRef<_>> from a pinned reference. This is similar to VRef::new.
Sourcepub unsafe fn from_raw(vtable: NonNull<T::VTable>, ptr: NonNull<u8>) -> Self
pub unsafe fn from_raw(vtable: NonNull<T::VTable>, ptr: NonNull<u8>) -> Self
Create a new VRef from raw pointers
§Safety
The ptr needs to be a valid object fitting the vtable.
Both vtable and ptr lifetime must outlive ’a
Sourcepub fn downcast<X: HasStaticVTable<T>>(&self) -> Option<&X>
pub fn downcast<X: HasStaticVTable<T>>(&self) -> Option<&X>
Return a reference of the given type if the type is matching.
Sourcepub fn downcast_pin<X: HasStaticVTable<T>>(
this: Pin<Self>,
) -> Option<Pin<&'a X>>
pub fn downcast_pin<X: HasStaticVTable<T>>( this: Pin<Self>, ) -> Option<Pin<&'a X>>
Return a reference of the given type if the type is matching
Trait Implementations§
impl<'a, T: ?Sized + VTableMeta> Copy for VRef<'a, T>
Auto Trait Implementations§
impl<'a, T> Freeze for VRef<'a, T>where
T: ?Sized,
impl<'a, T> RefUnwindSafe for VRef<'a, T>
impl<'a, T> !Send for VRef<'a, T>
impl<'a, T> !Sync for VRef<'a, T>
impl<'a, T> Unpin for VRef<'a, T>where
T: ?Sized,
impl<'a, T> UnwindSafe for VRef<'a, T>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more