#[repr(transparent)]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
sourceimpl<'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
sourceimpl<'a, T: ?Sized + VTableMeta> Clone for VRef<'a, T>
impl<'a, T: ?Sized + VTableMeta> Clone for VRef<'a, T>
sourceimpl<'a, T: ?Sized + VTableMeta> Deref for VRef<'a, T>
impl<'a, T: ?Sized + VTableMeta> Deref for VRef<'a, T>
impl<'a, T: ?Sized + VTableMeta> Copy for VRef<'a, T>
Auto Trait Implementations
impl<'a, T: ?Sized> RefUnwindSafe for VRef<'a, T> where
<T as VTableMeta>::Target: RefUnwindSafe,
impl<'a, T> !Send for VRef<'a, T>
impl<'a, T> !Sync for VRef<'a, T>
impl<'a, T: ?Sized> Unpin for VRef<'a, T>
impl<'a, T: ?Sized> UnwindSafe for VRef<'a, T> where
<T as VTableMeta>::Target: RefUnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more