Struct VBox

Source
pub struct VBox { /* private fields */ }
Expand description

A type erased Box of trait object that stores the vtable pointer.

This is just like a Box<dyn Trait> but erases type Trait so that the channel for sending it does not need to have Trait as one of its type parameters. Only the sending end and the receiving end need to agree on the type parameters.

Internally, it stores the trait object’s data pointer in a Box<dyn Any>, so that the Drop::drop() will be called when the wrapper is dropped. And it stores the vtable pointer in another usize to make sure it is Send.

Implementations§

Source§

impl VBox

Source

pub fn new(data: Box<dyn Any + Send>, vtable: usize, type_id: TypeId) -> Self

Create a new VBox. Do not use it directly. Use into_vbox! instead.

Source

pub fn unpack(self) -> (Box<dyn Any + Send>, usize, TypeId)

Unpack the VBox and return the fields to rebuild the original trait object. Do not use it directly. Use from_vbox! instead.

Auto Trait Implementations§

§

impl Freeze for VBox

§

impl !RefUnwindSafe for VBox

§

impl Send for VBox

§

impl !Sync for VBox

§

impl Unpin for VBox

§

impl !UnwindSafe for VBox

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>,

Source§

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>,

Source§

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.