vtable_indirect

Macro vtable_indirect 

Source
macro_rules! vtable_indirect {
    ($ty:ty => $($traits:ident),* $(,)?) => { ... };
    (@display $ty:ty; Display $(, $($rest:ident),*)?) => { ... };
    (@display $ty:ty; $other:ident $(, $($rest:ident),*)?) => { ... };
    (@display $ty:ty;) => { ... };
    (@debug $ty:ty; Debug $(, $($rest:ident),*)?) => { ... };
    (@debug $ty:ty; $other:ident $(, $($rest:ident),*)?) => { ... };
    (@debug $ty:ty;) => { ... };
    (@hash $ty:ty; Hash $(, $($rest:ident),*)?) => { ... };
    (@hash $ty:ty; $other:ident $(, $($rest:ident),*)?) => { ... };
    (@hash $ty:ty;) => { ... };
    (@partial_eq $ty:ty; PartialEq $(, $($rest:ident),*)?) => { ... };
    (@partial_eq $ty:ty; $other:ident $(, $($rest:ident),*)?) => { ... };
    (@partial_eq $ty:ty;) => { ... };
    (@partial_cmp $ty:ty; PartialOrd $(, $($rest:ident),*)?) => { ... };
    (@partial_cmp $ty:ty; $other:ident $(, $($rest:ident),*)?) => { ... };
    (@partial_cmp $ty:ty;) => { ... };
    (@cmp $ty:ty; Ord $(, $($rest:ident),*)?) => { ... };
    (@cmp $ty:ty; $other:ident $(, $($rest:ident),*)?) => { ... };
    (@cmp $ty:ty;) => { ... };
}
Expand description

Creates a VTableIndirect for generic container types by specifying which traits it implements.

Note: drop_in_place, default_in_place, and clone_into are NOT set by this macro. These per-type operations belong in TypeOps on the crate::Shape, which allows vtables to be shared across generic instantiations.

This macro generates wrapper functions that:

  1. Extract &T from OxPtrConst via ox.get::<T>()
  2. Call the trait method
  3. Wrap the result in Some(...)

§Standard traits

  • Display -> generates display fn calling <T as Display>::fmt
  • Debug -> generates debug fn calling <T as Debug>::fmt
  • Hash -> generates hash fn calling <T as Hash>::hash
  • PartialEq -> generates partial_eq fn calling <T as PartialEq>::eq
  • PartialOrd -> generates partial_cmp fn calling <T as PartialOrd>::partial_cmp
  • Ord -> generates cmp fn calling <T as Ord>::cmp

§Example

// Simple usage with standard traits
const VTABLE: VTableIndirect = vtable_indirect!(std::path::Path =>
    Debug,
    Hash,
    PartialEq,
    PartialOrd,
    Ord,
);