VTable

Trait VTable 

Source
pub trait VTable<T> {
    // Required method
    fn build_vtable() -> Self;
}
Expand description

VTable defines a type that represents a virtual function table for some type T.

T is different than a type that can be turned into a trait object like Box<dyn Any> because a VTable effectively decouples the type’s behaviour from the data it contains.

This mechanism allows the virtual function table to be attached to a homogeneous container, to prevent storing duplicates of these tables for each type instance stored in the container.

This is precisely how it is used to build VecDyn<V>, which is generic over the virtual table rather than the type itself.

Required Methods§

Source

fn build_vtable() -> Self

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: Copy> VTable<T> for ()

Source§

impl<T: DropBytes, V: VTable<T>> VTable<T> for (DropFn, V)

Implementors§