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:
- Convert
SEXParguments to Rust types - Convert Rust return values to SEXP
- Return structured argument errors inside the shim’s unwind boundary
The shims convert their arguments themselves, with the C wrappers’
structured kind = "conversion" condition (#2029); this module holds the
other conversions: return values, the View’s arguments and results, and
the arity check.
§Error Handling
These helpers panic with a diagnostic on conversion or argument-count
failure. The shim’s with_r_unwind_protect_shim catches it, so Rust-owned
values are dropped before returning across the C ABI. A View re-panics with
that condition for the consumer’s outer boundary. Call these helpers only
inside such a boundary: their panics must not cross a C ABI unguarded.
§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.
- from_
sexp ⚠ - Convert an R SEXP to a Rust type, panicking on failure.
- missing_
to_ ⚠sexp - Convert a
Missing<T>trait-method argument to the SEXP the vtable shim receives:Missing::Absentis R’s missing-argument sentinel, which the shim’sTryFromSexp for Missing<T>reads back asAbsent(the same sentinel an R wrapper forwards for an omitted argument), andPresent(value)convertsvaluewithto_sexp, soTneedsIntoRlike any other argument type (Missing<AsNumeric>crosses as the sentinel or the number). - nil⚠
- Return R’s
NULLvalue. - to_sexp⚠
- Convert a Rust value to an R SEXP.
- try_
from_ ⚠sexp - Convert an R SEXP to a Rust type, returning a Result.