Struct vtable::VRefMut

source ·
pub struct VRefMut<'a, T: ?Sized + VTableMeta> { /* private fields */ }
Expand description

VRefMut<'a MyTraitVTable> can be thought as a &'a mut dyn MyTrait

It will dereference to a structure that has the same members as MyTrait.

Implementations§

source§

impl<'a, T: ?Sized + VTableMeta> VRefMut<'a, T>

source

pub fn new<X: HasStaticVTable<T>>(value: &'a mut X) -> Self

Create a new VRef from a mutable 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)

source

pub unsafe fn from_raw(vtable: NonNull<T::VTable>, ptr: NonNull<u8>) -> Self

Create a new VRefMut from raw pointers

§Safety

The ptr needs to be a valid object fitting the vtable. Both vtable and ptr lifetime must outlive ’a. Can create mutable reference to ptr, so no other code can create mutable reference of ptr during the life time ’a.

source

pub fn borrow(&self) -> VRef<'_, T>

Borrow this to obtain a VRef.

source

pub fn borrow_mut(&mut self) -> VRefMut<'_, T>

Borrow this to obtain a new VRefMut.

source

pub fn into_ref(self) -> VRef<'a, T>

Create a VRef with the same lifetime as the original lifetime.

source

pub fn downcast<X: HasStaticVTable<T>>(&mut self) -> Option<&mut X>

Return a reference of the given type if the type is matching.

Trait Implementations§

source§

impl<'a, T: ?Sized + VTableMeta> Deref for VRefMut<'a, T>

§

type Target = <T as VTableMeta>::Target

The resulting type after dereferencing.
source§

fn deref(&self) -> &Self::Target

Dereferences the value.
source§

impl<'a, T: ?Sized + VTableMeta> DerefMut for VRefMut<'a, T>

source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.

Auto Trait Implementations§

§

impl<'a, T: ?Sized> RefUnwindSafe for VRefMut<'a, T>

§

impl<'a, T> !Send for VRefMut<'a, T>

§

impl<'a, T> !Sync for VRefMut<'a, T>

§

impl<'a, T: ?Sized> Unpin for VRefMut<'a, T>

§

impl<'a, T> !UnwindSafe for VRefMut<'a, T>

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

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

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

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.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.