Expand description
Storage-directed conversion to R.
This module provides IntoRAs, a trait for converting Rust values to R SEXPs
with explicit target storage type selection.
§Value-Based Semantics
Conversions are runtime-checked: if the actual value fits the target type, it converts; if not, it errors. There is no “lossy” escape hatch - if you want lossy conversion, cast the values yourself first.
§Example
ⓘ
use miniextendr_api::IntoRAs;
// These succeed (values fit)
let x = vec![1_i64, 2, 3];
let sexp = x.into_r_as::<i32>()?; // OK: all values in i32 range
let y = vec![1.0_f64, 2.0, 3.0];
let sexp = y.into_r_as::<i32>()?; // OK: all values are integral
// These fail (values don't fit)
let z = vec![1_i64 << 40];
let sexp = z.into_r_as::<i32>()?; // Error: out of range
let w = vec![1.5_f64];
let sexp = w.into_r_as::<i32>()?; // Error: not integral
// User wants lossy? Cast first.
let lossy: Vec<i32> = vec![1.5_f64, 2.7].iter().map(|&x| x as i32).collect();
let sexp = lossy.into_r(); // [1, 2] - user's responsibilityMacros§
- impl_
into_ 🔒r_ as_ f64_ scalar - impl_
into_ 🔒r_ as_ i32_ scalar - impl_
into_ 🔒r_ as_ u8_ scalar - impl_
vec_ 🔒into_ r_ as_ f64 - impl_
vec_ 🔒into_ r_ as_ f64_ infallible - impl_
vec_ 🔒into_ r_ as_ i32 - impl_
vec_ 🔒into_ r_ as_ u8
Enums§
- Coerce
Error 🔒Kind - Internal enum to unify different coerce error types.
- Storage
Coerce Error - Error type for storage-directed conversion failures.
Traits§
- IntoRAs
- Storage-directed conversion to R SEXP.
Functions§
- map_
coerce_ 🔒error - try_
coerce_ 🔒scalar - Try to coerce a scalar value, mapping CoerceError to StorageCoerceError.