Skip to main content

Module into_r_as

Module into_r_as 

Source
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 responsibility

Macros§

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§

CoerceErrorKind 🔒
Internal enum to unify different coerce error types.
StorageCoerceError
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.