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,
    class_system: ClassSystem,
    blanket: bool,
    internal: bool,
    noexport: bool,
) -> 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_{TRAIT}_FOR_{TYPE}: {Trait}VTable constant
  • 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)
  • class_system: Which R class system (env, r6, s3, s4, s7) to generate wrappers for
  • blanket: If true, skip emitting the impl block (a blanket impl already provides it)
  • internal: If true, add @keywords internal to R documentation
  • noexport: If true, suppress @export in R documentation