vtable_direct

Macro vtable_direct 

Source
macro_rules! vtable_direct {
    ($ty:ty => $($rest:tt)*) => { ... };
    (@build $ty:ty, $builder:expr, $(,)?) => { ... };
    (@build $ty:ty, $builder:expr, Display $(, $($rest:tt)*)?) => { ... };
    (@build $ty:ty, $builder:expr, Debug $(, $($rest:tt)*)?) => { ... };
    (@build $ty:ty, $builder:expr, Hash $(, $($rest:tt)*)?) => { ... };
    (@build $ty:ty, $builder:expr, PartialEq, $($rest:tt)*) => { ... };
    (@build $ty:ty, $builder:expr, PartialEq $(,)?) => { ... };
    (@build $ty:ty, $builder:expr, PartialOrd $(, $($rest:tt)*)?) => { ... };
    (@build $ty:ty, $builder:expr, Ord $(, $($rest:tt)*)?) => { ... };
    (@build $ty:ty, $builder:expr, FromStr $(, $($rest:tt)*)?) => { ... };
    (@build $ty:ty, $builder:expr, [parse = $f:expr] $(, $($rest:tt)*)?) => { ... };
    (@build $ty:ty, $builder:expr, [invariants = $f:expr] $(, $($rest:tt)*)?) => { ... };
    (@build $ty:ty, $builder:expr, [try_from = $f:expr] $(, $($rest:tt)*)?) => { ... };
    (@build $ty:ty, $builder:expr, [try_into_inner = $f:expr] $(, $($rest:tt)*)?) => { ... };
    (@build $ty:ty, $builder:expr, [try_borrow_inner = $f:expr] $(, $($rest:tt)*)?) => { ... };
}
Expand description

Creates a VTableDirect for a type 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.

Standard traits (auto-generated from trait method references):

  • Display -> .display(<T as Display>::fmt)
  • Debug -> .debug(<T as Debug>::fmt)
  • Hash -> .hash(<T as Hash>::hash::<HashProxy>)
  • PartialEq -> .partial_eq(<T as PartialEq>::eq)
  • PartialOrd -> .partial_cmp(<T as PartialOrd>::partial_cmp)
  • Ord -> .cmp(<T as Ord>::cmp)
  • FromStr -> .parse(...) (generates a parse function)

Custom functions (passed directly):

  • [parse = fn_name]
  • [invariants = fn_name]
  • [try_from = fn_name]
  • [try_into_inner = fn_name]
  • [try_borrow_inner = fn_name]

§Example

const VTABLE: VTableDirect = vtable_direct!(char =>
    [parse = parse],
    Display,
    Debug,
    Hash,
    PartialEq,
    PartialOrd,
    Ord,
);