Expand description
Unified C wrapper generation for standalone functions and impl methods.
This module provides shared infrastructure for generating C wrappers that:
- Run on Rβs main thread inside
with_r_unwind_protect - Perform parameter conversion from SEXP to Rust types
- Convert Rust return values back to SEXP
- Properly handle panics and R errors
The same infrastructure is used by both #[miniextendr] on standalone functions
and #[miniextendr(env|r6|s3|s4|s7)] on impl blocks.
Re-exportsΒ§
use proc_macro2::TokenStream;πuse quote::format_ident;πuse quote::quote;π
StructsΒ§
- CWrapper
Context - All information needed to generate a C wrapper function for an R-exported Rust item.
- CWrapper
Context Builder - Builder for
CWrapperContext.
EnumsΒ§
- ErrParts
Mode - How the generated
Errarm turns an error value into condition parts (message, class vector, structured data). - Return
Handling - Strategy for converting a Rust return value into an R
SEXP.
FunctionsΒ§
- detect_
return_ handling - Detects the
ReturnHandlingstrategy from a return type: the one rule for standalone functions, inherent methods and trait methods. - detect_
return_ πhandling_ from_ type - Determines the
ReturnHandlingvariant for a concretesyn::Type. - first_
type_ πargument - Extracts the first generic type argument from a path segmentβs angle-bracketed arguments.
- into_
r_ πerr_ value - The tagged condition value of a failed return conversion, the error bound
to
__mx_error(return_conversion). - return_
conversion π - The conversion of a returned value to the
SEXPa generated entry point returns (#2272):IntoR::try_into_sexp(value), and a failed conversion becomes the tagged condition value of aResulterror (kind = "result_err"): the errorβs message, classes and fields, read throughRConditionData, which everyIntoR::Errorimplements (condition::into_r_err_parts). No panic, so no framework file location in the message. - return_
conversion_ πat return_conversionwith thetry_into_sexppath spanned atspan, so a value withoutIntoRis reported there.- return_
conversion_ πresult return_conversionas aResult<SEXP, SEXP>:Okthe converted value,Errthe tagged condition value of a failed conversion, for a getter that keeps a converted value and must not keep a condition (a cached field, #2271).