Skip to main content

Module conv

Module conv 

Source
Expand description

§Type Conversion Helpers for Method Shims

This module provides type conversion functions used by the generated method shims from #[miniextendr] traits. These functions wrap the existing TryFromSexp and IntoR traits with appropriate error handling.

§Purpose

Method shims generated by #[miniextendr] traits need to:

  1. Convert SEXP arguments to Rust types
  2. Convert Rust return values to SEXP
  3. Handle conversion errors gracefully (via R errors)

This module provides a uniform interface for these conversions.

§Error Handling

Conversion errors raise R errors (via Rf_error), which unwinds back to R. This ensures that:

  • Invalid arguments produce helpful error messages
  • R’s error handling mechanism is used consistently
  • No Rust panics escape to R

§Thread Safety

All functions in this module must be called on R’s main thread, as they interact with R’s SEXP values and error handling.

Functions§

check_arity
Check that the number of arguments matches expected arity.
extract_arg
Extract and convert an argument from argv with bounds checking.
from_sexp
Convert an R SEXP to a Rust type, aborting via Rf_error on failure.
nil
Return R’s NULL value.
rf_error
Raise an R error with the given message.
to_sexp
Convert a Rust value to an R SEXP.
try_from_sexp
Convert an R SEXP to a Rust type, returning a Result.