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" 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 parameters are rewritten to ExternalPtr<Type> for the C wrapper, then dereferenced to &Type when calling the actual trait method.