Skip to main content

generate_vtable_static

Function generate_vtable_static 

Source
pub(super) fn generate_vtable_static(
    impl_item: &ItemImpl,
    trait_path: &Path,
    concrete_type: &Type,
    impl_attrs: &ImplAttrs,
    abi: &TraitAbiMetadata,
    declaration: &[TraitItemFn],
    defaults: &[ImplItemFn],
) -> TokenStream
Expand description

Generate the vtable static, C wrappers, R wrappers, and call defs for a trait implementation.

This is the main entry point for trait impl codegen. For a given impl Trait for Type { ... } block, it produces:

  • The cleaned original impl block (with #[miniextendr] attrs stripped from methods)
  • A static __VTABLE_{crate}_{Trait}_FOR_{Type} with the declared repr(C) layout
  • C wrapper functions and R_CallMethodDef entries for each method and const
  • R wrapper code string (class-system specific)
  • Two const items: {TYPE}_{TRAIT}_CALL_DEFS and R_WRAPPERS_{TYPE}_{TRAIT}_IMPL

§Arguments

  • impl_item: The parsed impl Trait for Type block
  • trait_path: Full path to the trait (e.g., crate::Counter)
  • concrete_type: The implementing type (e.g., MyCounter)
  • impl_attrs: The impl block’s options. The class system picks the R wrapper generator; blanket skips emitting the impl block (a blanket impl already provides it); internal / noexport control the roxygen export tags; no_preconditions drops the R-side type checks, as on an inherent impl.
  • abi: The canonical trait name, fingerprint and callback layout from the declaration.