Struct vtable::VBox

source ·
pub struct VBox<T: ?Sized + VTableMetaDrop> { /* private fields */ }
Expand description

An equivalent of a Box that holds a pointer to a VTable and a pointer to an instance. A VBox frees the instance when dropped.

The type parameter is supposed to be the VTable type.

The VBox implements Deref so one can access all the members of the vtable.

This is only valid if the VTable has a drop function (so that the #[vtable] macro implements the VTableMetaDrop trait for it)

Implementations§

source§

impl<T: ?Sized + VTableMetaDrop> VBox<T>

source

pub fn new<X: HasStaticVTable<T>>(value: X) -> Self

Create a new VBox from an instance of a type that can be associated with a VTable.

Will move the instance on the heap.

(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 VBox from raw pointers

§Safety

The ptr needs to be a valid object fitting the vtable. ptr must be properly allocated so it can be dropped.

source

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

Gets a VRef pointing to this box

source

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

Gets a VRefMut pointing to this box

source

pub fn leak(self) -> VRefMut<'static, T>

Leaks the content of the box.

Trait Implementations§

source§

impl<T: ?Sized + VTableMetaDrop> Deref for VBox<T>

§

type Target = <T as VTableMeta>::Target

The resulting type after dereferencing.
source§

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

Dereferences the value.
source§

impl<T: ?Sized + VTableMetaDrop> DerefMut for VBox<T>

source§

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

Mutably dereferences the value.
source§

impl<T: ?Sized + VTableMetaDrop> Drop for VBox<T>

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<T: ?Sized> Freeze for VBox<T>

§

impl<T: ?Sized> RefUnwindSafe for VBox<T>

§

impl<T> !Send for VBox<T>

§

impl<T> !Sync for VBox<T>

§

impl<T: ?Sized> Unpin for VBox<T>
where <T as VTableMeta>::Target: Unpin,

§

impl<T: ?Sized> UnwindSafe for VBox<T>
where <T as VTableMeta>::Target: UnwindSafe,

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.