VTable

Trait VTable 

Source
pub unsafe trait VTable: Clone {
    type Bounds: IsBound;
    type Id: PartialEq + Eq;

    // Required methods
    fn descriptor(&self) -> &Descriptor<Self::Id>;
    fn bound_impl(&self) -> &BoundsImpl<Self::Bounds>;
}
Expand description

Virtual method table and type descriptor.

Rust automatically generates vtables for trait objects. However, its not currently possible to access these vtables directly on stable. Instead, this trait provides a unified interface for custom vtables. Custom vtables can be generated thanks to Rust’s ability to static promote constants to give them stable addresses.

A vtable is created from a type Descriptor and a BoundsImpl. A Descriptor describes a type, and includes things like the type’s size and name. The Descriptor::is_type() method can be used to check if a vtable is for a particular type. A BoundsImpl contains the implementations of the virtual methods for the type. Currently, only Drop, Clone, and Debug are included in the virtual methods.

All dungeon_cell types use this trait as the basis for their type erasure.

Use VTableOf or ConstVTableOf to construct a instance of a generic vtable for a type. Additionally, use VTableSubset to reduce the number of traits bound by Self::Bounds.

§Safety

Required Associated Types§

Source

type Bounds: IsBound

The dynamic trait bounds applied.

This may not match the trait bounds used when creating the vtable, but it will always be equal to or a subset of it.

Source

type Id: PartialEq + Eq

Type to store the ID information for which type the vtable is for.

ID types must always implement Eq to allow comparing them.

Required Methods§

Source

fn descriptor(&self) -> &Descriptor<Self::Id>

Get the type descriptor.

This is the descriptor for the type the vtable was made for.

Source

fn bound_impl(&self) -> &BoundsImpl<Self::Bounds>

Get the bound implementation.

This is the method implementation for the type the vtable was made for.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl<T: VTable> VTable for &T

Source§

type Bounds = <T as VTable>::Bounds

Source§

type Id = <T as VTable>::Id

Source§

fn descriptor(&self) -> &Descriptor<Self::Id>

Source§

fn bound_impl(&self) -> &BoundsImpl<Self::Bounds>

Implementors§