Skip to main content

generate_method_c_wrapper

Function generate_method_c_wrapper 

Source
pub fn generate_method_c_wrapper(
    parsed_impl: &ParsedImpl,
    method: &ParsedMethod,
) -> TokenStream
Expand description

Generate a C-callable wrapper function for a single method in an impl block.

Produces a #[no_mangle] extern "C-unwind" function named C_{crate}_{Type}__{method} that:

  1. Accepts SEXP arguments (including self_sexp for instance methods)
  2. Extracts &self / &mut self from an ErasedExternalPtr for instance methods
  3. Converts SEXP arguments to Rust types
  4. Calls the actual Rust method
  5. Converts the return value back to SEXP

The wrapper runs on R’s main thread.

Also emits an R_CallMethodDef constant for R routine registration.

§Arguments

  • parsed_impl - The parsed impl block providing type identity, cfg attrs, and options
  • method - The parsed method to generate a wrapper for