Skip to main content

generate_trait_method_c_wrapper

Function generate_trait_method_c_wrapper 

Source
pub(super) fn generate_trait_method_c_wrapper(
    method: &TraitMethod,
    type_ident: &Ident,
    trait_name: &Ident,
    trait_path: &Path,
) -> TokenStream
Expand description

Generate a C wrapper function and R_CallMethodDef for a single trait method.

Uses CWrapperContext builder to produce:

  • An extern "C-unwind" function callable from R via .Call()
  • A R_CallMethodDef constant for symbol registration

Instance methods (has_self) extract the object via ErasedExternalPtr::from_sexp and call with fully-qualified trait syntax <Type as Trait>::method(self_ref, ...). Static methods run on the worker thread when the worker flag is set.

&Self / &mut Self parameters are borrowed external arguments (#2106): the C wrapper converts each to its ExternalPtr<Type> handle and borrows it with the declared mutability for the call, after checking that no two of them alias while one is mutable.