Skip to main content

generate_method_shim

Function generate_method_shim 

Source
fn generate_method_shim(
    trait_name: &Ident,
    method: &MethodInfo,
    extra_bounds: &ExtraBounds,
    trait_param_idents: &[&Ident],
    trait_type_params: &[&GenericParam],
    trait_where_clause: &Option<WhereClause>,
) -> TokenStream
Expand description

Generate a method shim function for a trait method.

The shim is an extern "C" function that:

  1. Checks argument arity
  2. Wraps everything in with_r_unwind_protect to prevent unwinding across FFI
  3. Converts SEXP arguments to Rust types
  4. Calls the actual method on the concrete type
  5. Converts the result back to SEXP
  6. On panic, converts to R error via with_r_unwind_protect

For generic traits, the shim carries the trait’s type parameters plus __ImplT.