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, inside with_r_unwind_protect_shim:

  1. Checks argument arity
  2. Refuses aliased native borrows among the arguments
  3. Converts SEXP arguments to Rust types
  4. Calls the actual method on the concrete type
  5. Converts the result back to SEXP

A panic in any step comes back as a tagged condition SEXP, which the View re-panics with. generate_concrete_vtable_shims emits the same steps for a generic trait’s impls.

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