Skip to main content

IntoR

Trait IntoR 

Source
pub trait IntoR {
    type Error: Display;

    // Required method
    fn try_into_sexp(self) -> Result<SEXP, Self::Error>;

    // Provided methods
    unsafe fn try_into_sexp_unchecked(self) -> Result<SEXP, Self::Error>
       where Self: Sized { ... }
    fn into_sexp(self) -> SEXP
       where Self: Sized { ... }
    unsafe fn into_sexp_unchecked(self) -> SEXP
       where Self: Sized { ... }
}
Expand description

Trait for converting Rust types to R SEXP values.

§Required Method

Implementors must provide try_into_sexp and specify Error. The other three methods have sensible defaults.

§Examples

use miniextendr_api::into_r::IntoR;

let sexp = 42i32.into_sexp();
let sexp = "hello".to_string().into_sexp();

// Fallible path:
let result = "hello".try_into_sexp();
assert!(result.is_ok());

Required Associated Types§

Source

type Error: Display

The error type for fallible conversions.

Use std::convert::Infallible for types that can never fail. Use IntoRError for types that may fail (e.g. strings exceeding R’s i32 length limit).

Required Methods§

Source

fn try_into_sexp(self) -> Result<SEXP, Self::Error>

Try to convert this value to an R SEXP.

This is the required method. All other methods delegate to it.

Provided Methods§

Source

unsafe fn try_into_sexp_unchecked(self) -> Result<SEXP, Self::Error>
where Self: Sized,

Try to convert to SEXP without thread safety checks.

§Safety

Must be called from R’s main thread.

Source

fn into_sexp(self) -> SEXP
where Self: Sized,

Convert this value to an R SEXP, panicking on error.

In debug builds, asserts that we’re on R’s main thread.

Source

unsafe fn into_sexp_unchecked(self) -> SEXP
where Self: Sized,

Convert to SEXP without thread safety checks, panicking on error.

§Safety

Must be called from R’s main thread. In debug builds, this still calls the checked version by default, but implementations may skip thread assertions for performance.

Implementations on Foreign Types§

Source§

impl IntoR for &str

Source§

impl IntoR for &OsStr

Convert &OsStr to R character scalar.

Source§

impl IntoR for &Path

Convert &Path to R character scalar.

Source§

impl IntoR for &[&str]

Convert &&str to R character vector (STRSXP).

Source§

impl IntoR for &[bool]

Convert &[bool] to R logical vector.

Source§

impl IntoR for &[f32]

Source§

impl IntoR for &[i8]

Source§

impl IntoR for &[i16]

Source§

impl IntoR for &[u16]

Source§

impl IntoR for &[String]

Convert &[String] to R character vector (STRSXP).

Source§

impl IntoR for Cow<'_, str>

Convert Cow<'_, str> to R character scalar.

Source§

impl IntoR for Infallible

Source§

impl IntoR for Option<&str>

Source§

impl IntoR for Option<Rboolean>

Source§

impl IntoR for Option<bool>

Source§

impl IntoR for Option<f32>

Source§

impl IntoR for Option<f64>

Source§

impl IntoR for Option<i8>

Source§

impl IntoR for Option<i16>

Source§

impl IntoR for Option<i32>

Source§

impl IntoR for Option<i64>

Source§

impl IntoR for Option<isize>

Source§

impl IntoR for Option<u16>

Source§

impl IntoR for Option<u32>

Source§

impl IntoR for Option<u64>

Source§

impl IntoR for Option<usize>

Source§

impl IntoR for Option<RLogical>

Source§

impl IntoR for Option<Rcomplex>

Source§

impl IntoR for Option<BTreeSet<String>>

Convert Option<BTreeSet<String>> to R: Some(set) -> character vector, None -> NULL.

Source§

impl IntoR for Option<String>

Source§

impl IntoR for Option<Vec<String>>

Convert Option<Vec<String>> to R: Some(vec) → character vector, None → NULL.

Source§

impl IntoR for Option<HashSet<String>>

Convert Option<HashSet<String>> to R: Some(set) -> character vector, None -> NULL.

Source§

impl IntoR for Option<OsString>

Convert Option<OsString> to R: Some(s) -> character, None -> NA_character_.

Source§

impl IntoR for Option<PathBuf>

Convert Option<PathBuf> to R: Some(path) -> character, None -> NA_character_.

Source§

impl IntoR for bool

Source§

impl IntoR for char

Source§

impl IntoR for f32

Source§

impl IntoR for f64

Source§

impl IntoR for i8

Source§

impl IntoR for i16

Source§

impl IntoR for i32

Source§

impl IntoR for i64

Convert i64 to R integer (INTSXP) or numeric (REALSXP).

Uses smart conversion: values in (i32::MIN, i32::MAX] are returned as R integers for exact representation. Values outside that range (including i32::MIN which is NA_integer_ in R) fall back to R doubles.

let small: i64 = 42;
small.into_sexp(); // R integer 42L

let big: i64 = 3_000_000_000;
big.into_sexp(); // R double 3e9

let na_trap: i64 = i32::MIN as i64;
na_trap.into_sexp(); // R double (not NA_integer_!)
Source§

impl IntoR for isize

Convert isize to R integer (INTSXP) or numeric (REALSXP).

On 64-bit platforms, uses the same smart conversion as i64(impl IntoR for i64). On 32-bit platforms, isize fits in i32 so conversion is always exact.

Source§

impl IntoR for u8

Source§

impl IntoR for u16

Source§

impl IntoR for u32

Source§

impl IntoR for u64

Convert u64 to R integer (INTSXP) or numeric (REALSXP).

Values in [0, i32::MAX] are returned as R integers. Larger values fall back to R doubles (which may lose precision above 2^53).

Source§

impl IntoR for ()

Source§

impl IntoR for usize

Convert usize to R integer (INTSXP) or numeric (REALSXP).

Values in [0, i32::MAX] are returned as R integers. Larger values fall back to R doubles.

Source§

impl IntoR for Box<[Cow<'_, str>]>

Convert Box<[Cow<'_, str>]> to R character vector (STRSXP).

Source§

impl IntoR for Box<[bool]>

Convert Box<[bool]> to R logical vector.

Source§

impl IntoR for Box<[String]>

Convert Box<[String]> to R character vector (STRSXP).

Source§

impl IntoR for BTreeSet<i8>

Source§

impl IntoR for BTreeSet<i16>

Source§

impl IntoR for BTreeSet<u16>

Source§

impl IntoR for BTreeSet<String>

Convert BTreeSet<String> to R character vector.

Source§

impl IntoR for String

Source§

impl IntoR for Vec<&str>

Convert Vec<&str> to R character vector (STRSXP).

Source§

impl IntoR for Vec<Cow<'_, str>>

Convert Vec<Cow<'_, str>> to R character vector (STRSXP).

Source§

impl IntoR for Vec<Option<Rboolean>>

Convert Vec<Option<Rboolean>> to R logical vector with NA support.

Source§

impl IntoR for Vec<Option<Cow<'_, str>>>

Convert Vec<Option<Cow<'_, str>>> to R character vector with NA support.

None values become NA_character_ in R.

Source§

impl IntoR for Vec<Option<bool>>

Convert Vec<Option<bool>> to R logical vector with NA support.

Source§

impl IntoR for Vec<Option<f32>>

Source§

impl IntoR for Vec<Option<f64>>

Source§

impl IntoR for Vec<Option<i8>>

Source§

impl IntoR for Vec<Option<i16>>

Source§

impl IntoR for Vec<Option<i32>>

Source§

impl IntoR for Vec<Option<i64>>

Source§

impl IntoR for Vec<Option<isize>>

Source§

impl IntoR for Vec<Option<u16>>

Source§

impl IntoR for Vec<Option<u32>>

Source§

impl IntoR for Vec<Option<u64>>

Source§

impl IntoR for Vec<Option<usize>>

Source§

impl IntoR for Vec<Option<RLogical>>

Convert Vec<Option<RLogical>> to R logical vector with NA support.

Source§

impl IntoR for Vec<Option<String>>

Convert Vec<Option<String>> to R character vector with NA support.

None values become NA_character_ in R.

Source§

impl IntoR for Vec<Option<OsString>>

Convert Vec<Option<OsString>> to R character vector with NA support.

Source§

impl IntoR for Vec<Option<PathBuf>>

Convert Vec<Option<PathBuf>> to R character vector with NA support.

Source§

impl IntoR for Vec<bool>

Convert Vec<bool> to R logical vector.

Source§

impl IntoR for Vec<f32>

Source§

impl IntoR for Vec<i8>

Source§

impl IntoR for Vec<i16>

Source§

impl IntoR for Vec<i64>

Source§

impl IntoR for Vec<isize>

Source§

impl IntoR for Vec<u16>

Source§

impl IntoR for Vec<u64>

Source§

impl IntoR for Vec<usize>

Source§

impl IntoR for Vec<Box<[String]>>

Convert Vec<Box<[String]>> to R list of character vectors.

Source§

impl IntoR for Vec<BTreeSet<String>>

Convert Vec<BTreeSet<String>> to R list of character vectors.

Source§

impl IntoR for Vec<String>

Convert Vec<String> to R character vector (STRSXP).

Source§

impl IntoR for Vec<Vec<String>>

Convert Vec<Vec<String>> to R list of character vectors.

Source§

impl IntoR for Vec<HashSet<String>>

Convert Vec<HashSet<String>> to R list of character vectors.

Source§

impl IntoR for Vec<OsString>

Convert Vec<OsString> to R character vector.

Source§

impl IntoR for Vec<PathBuf>

Convert Vec<PathBuf> to R character vector.

Source§

impl IntoR for HashSet<i8>

Source§

impl IntoR for HashSet<i16>

Source§

impl IntoR for HashSet<u16>

Source§

impl IntoR for HashSet<String>

Convert HashSet<String> to R character vector.

Source§

impl IntoR for OsString

Convert OsString to R character scalar.

On Unix, strings that are not valid UTF-8 will produce lossy output (invalid sequences replaced with U+FFFD).

Source§

impl IntoR for PathBuf

Convert PathBuf to R character scalar.

On Unix, paths that are not valid UTF-8 will produce lossy output (invalid sequences replaced with U+FFFD).

Source§

impl<A: IntoR, B: IntoR> IntoR for (A, B)

Source§

impl<A: IntoR, B: IntoR, C: IntoR> IntoR for (A, B, C)

Source§

impl<A: IntoR, B: IntoR, C: IntoR, D: IntoR> IntoR for (A, B, C, D)

Source§

impl<A: IntoR, B: IntoR, C: IntoR, D: IntoR, E: IntoR> IntoR for (A, B, C, D, E)

Source§

impl<A: IntoR, B: IntoR, C: IntoR, D: IntoR, E: IntoR, F: IntoR> IntoR for (A, B, C, D, E, F)

Source§

impl<A: IntoR, B: IntoR, C: IntoR, D: IntoR, E: IntoR, F: IntoR, G: IntoR> IntoR for (A, B, C, D, E, F, G)

Source§

impl<A: IntoR, B: IntoR, C: IntoR, D: IntoR, E: IntoR, F: IntoR, G: IntoR, H: IntoR> IntoR for (A, B, C, D, E, F, G, H)

Source§

impl<T> IntoR for &[T]
where T: RNativeType,

Source§

impl<T> IntoR for Cow<'_, [T]>
where T: RNativeType + Clone,

Convert Cow<'_, [T]> to R vector where T: RNativeType.

For Cow::Borrowed slices that came from R (e.g., via TryFromSexp), SEXP pointer recovery is attempted — if the borrowed data points into an R vector, the original SEXP is returned without copying. Otherwise falls through to the standard copy path.

Source§

impl<T> IntoR for Option<&T>
where T: Copy + IntoR,

Convert Option<&T> to R SEXP by copying the value.

  • Some(&v) → copies v and converts to R
  • None → returns NULL (R_NilValue)

Note: This returns NULL for None, not NA, since there’s no reference to return. Use Option<T> directly if you want NA semantics for scalar types.

Source§

impl<T> IntoR for Box<[T]>
where T: RNativeType,

Source§

impl<T> IntoR for BinaryHeap<T>
where T: RNativeType + Ord,

Convert BinaryHeap<T> to R vector where T: RNativeType + Ord.

The heap is drained into a vector (destroying the heap property). Elements are returned in arbitrary order, not sorted.

Source§

impl<T> IntoR for BTreeSet<T>
where T: RNativeType + Ord,

Convert BTreeSet<T> to R vector.

Source§

impl<T> IntoR for VecDeque<T>
where T: RNativeType,

Convert VecDeque<T> to R vector where T: RNativeType.

Source§

impl<T> IntoR for Vec<Box<[T]>>
where T: RNativeType,

Convert Vec<Box<[T]>> to R list of vectors (for RNativeType elements). Each boxed slice becomes an R vector.

Source§

impl<T> IntoR for Vec<Vec<T>>
where T: RNativeType,

Convert Vec<Vec<T>> to R list of vectors (VECSXP of typed vectors).

Source§

impl<T> IntoR for Vec<T>
where T: RNativeType,

Source§

impl<T> IntoR for HashSet<T>
where T: RNativeType + Eq + Hash,

Convert HashSet<T> to R vector.

Source§

impl<T, E> IntoR for Result<T, E>
where T: IntoR, E: Display,

Convert Result<T, E> to R (value-style, for #[miniextendr(unwrap_in_r)]).

§Behavior

  • Ok(value) → returns the converted value directly
  • Err(msg) → returns list(error = "<msg>") (value-style error)

§When This Is Used

This impl is only used when #[miniextendr(unwrap_in_r)] is specified. Without that attribute, #[miniextendr] functions returning Result<T, E> will unwrap in Rust and raise an R error on Err (error boundary semantics).

§Error Handling Summary

ModeOn Err(e)Bound Required
DefaultR error via panicE: Debug
unwrap_in_rlist(error = ...)E: Display

Default (without unwrap_in_r): Result<T, E> acts as an error boundary:

  • Ok(v)v converted to R
  • Err(e) → R error with Debug-formatted message (requires E: Debug)

With unwrap_in_r: Result<T, E> is passed through to R:

  • Ok(v)v converted to R
  • Err(e)list(error = e.to_string()) (requires E: Display)

§Example

// Default: error boundary - Err becomes R stop()
#[miniextendr]
fn divide(x: f64, y: f64) -> Result<f64, String> {
    if y == 0.0 { Err("division by zero".into()) }
    else { Ok(x / y) }
}
// In R: tryCatch(divide(1, 0), error = ...) catches the error

// Value-style: Err becomes list(error = ...)
#[miniextendr(unwrap_in_r)]
fn divide_safe(x: f64, y: f64) -> Result<f64, String> {
    if y == 0.0 { Err("division by zero".into()) }
    else { Ok(x / y) }
}
// In R: result <- divide_safe(1, 0)
//       if (!is.null(result$error)) { handle error }
Source§

impl<T, const N: usize> IntoR for Vec<[T; N]>
where T: RNativeType,

Convert Vec<[T; N]> to R list of vectors. Each array becomes an R vector.

Source§

impl<T: RNativeType + Eq + Hash> IntoR for Option<HashSet<T>>

Convert Option<HashSet<T>> to R: Some(set) -> vector, None -> NULL.

Source§

impl<T: RNativeType + Ord> IntoR for Option<BTreeSet<T>>

Convert Option<BTreeSet<T>> to R: Some(set) -> vector, None -> NULL.

Source§

impl<T: RNativeType> IntoR for Option<Vec<T>>

Convert Option<Vec<T>> to R: Some(vec) → vector, None → NULL.

Source§

impl<T: RNativeType> IntoR for Vec<BTreeSet<T>>

Convert Vec<BTreeSet<T>> to R list of vectors (for RNativeType elements). Each BTreeSet becomes an R vector (sorted).

Source§

impl<T: RNativeType> IntoR for Vec<HashSet<T>>

Convert Vec<HashSet<T>> to R list of vectors (for RNativeType elements). Each HashSet becomes an R vector (unordered).

Source§

impl<T: RNativeType, const N: usize> IntoR for [T; N]

Blanket impl for [T; N] where T: RNativeType.

Enables direct conversion of fixed-size arrays to R vectors. Useful for SHA hashes, fixed-size byte patterns, etc.

Source§

impl<T: IntoR> IntoR for Result<T, NullOnErr>

Convert Result<T, NullOnErr> to R, returning NULL on error.

This is a special case for Result<T, ()> types where the error carries no information. Instead of raising an R error, we return NULL.

Source§

impl<V: IntoR> IntoR for Option<BTreeMap<String, V>>

Convert Option<BTreeMap<String, V>> to R: Some(map) -> named list, None -> NULL.

Source§

impl<V: IntoR> IntoR for Option<HashMap<String, V>>

Convert Option<HashMap<String, V>> to R: Some(map) -> named list, None -> NULL.

Source§

impl<V: IntoR> IntoR for BTreeMap<String, V>

Convert BTreeMap<String, V> to R named list (VECSXP).

Source§

impl<V: IntoR> IntoR for Vec<BTreeMap<String, V>>

Convert Vec<BTreeMap<String, V>> to R list of named lists.

Source§

impl<V: IntoR> IntoR for Vec<HashMap<String, V>>

Convert Vec<HashMap<String, V>> to R list of named lists.

Source§

impl<V: IntoR> IntoR for HashMap<String, V>

Convert HashMap<String, V> to R named list (VECSXP).

Implementors§

Source§

impl IntoR for Rboolean

Source§

impl IntoR for AltrepSexp

Convert AltrepSexp to R by returning the inner SEXP.

This allows AltrepSexp to be used as a return type from #[miniextendr] functions, transparently passing the ALTREP SEXP back to R.

Source§

impl IntoR for DataFrameView

Source§

impl IntoR for RLogical

Source§

impl IntoR for Rcomplex

Source§

impl IntoR for SEXP

Source§

impl IntoR for List

Source§

impl IntoR for ListMut

Source§

impl IntoR for NamedList

Source§

impl IntoR for ProtectedStrVec

Source§

impl IntoR for StrVec

Source§

impl<I> IntoR for CollectNA<I>
where I: ExactSizeIterator<Item = Option<f64>>,

Source§

impl<I> IntoR for CollectNAInt<I>
where I: ExactSizeIterator<Item = Option<i32>>,

Source§

impl<I> IntoR for CollectStrings<I>
where I: ExactSizeIterator<Item = String>,

Source§

impl<I, T> IntoR for Collect<I>
where I: ExactSizeIterator<Item = T>, T: RNativeType,

Source§

impl<K: AsRef<str>, V: AtomicElement> IntoR for AsNamedVector<Vec<(K, V)>>

Source§

impl<K: AsRef<str>, V: AtomicElement, const N: usize> IntoR for AsNamedVector<[(K, V); N]>

Source§

impl<K: AsRef<str>, V: Clone + AtomicElement> IntoR for AsNamedVector<&[(K, V)]>

Source§

impl<K: AsRef<str>, V: Clone + IntoR> IntoR for AsNamedList<&[(K, V)]>

Source§

impl<K: AsRef<str>, V: IntoR> IntoR for AsNamedList<Vec<(K, V)>>

Source§

impl<K: AsRef<str>, V: IntoR, const N: usize> IntoR for AsNamedList<[(K, V); N]>

Source§

impl<T> IntoR for Altrep<T>

Convert Altrep<T> to R using ALTREP representation.

This creates an ALTREP object where the data stays in Rust and is provided to R on-demand through ALTREP callbacks.

Source§

impl<T: IntoDataFrame> IntoR for ToDataFrame<T>

Source§

impl<T: IntoExternalPtr> IntoR for AsExternalPtr<T>

Source§

impl<T: IntoExternalPtr> IntoR for T

Blanket impl: Types marked with IntoExternalPtr get automatic IntoR.

This wraps the value in ExternalPtr<T> automatically, so you can return MyType directly from #[miniextendr] functions instead of ExternalPtr<MyType>.

Source§

impl<T: TypedExternal> IntoR for ExternalPtr<T>

Source§

impl<T: RFactor> IntoR for FactorOptionVec<T>

Source§

impl<T: RFactor> IntoR for FactorVec<T>

Source§

impl<T: RNativeType> IntoR for AsRNative<T>

Source§

impl<T: RNativeType, const NDIM: usize> IntoR for RArray<T, NDIM>

Source§

impl<T: IntoList> IntoR for AsList<T>

Source§

impl<T: IntoList> IntoR for DataFrame<T>

IntoR implementation for DataFrame.

This allows DataFrame to be returned directly from #[miniextendr] functions.

Source§

impl<T: Display> IntoR for AsDisplay<T>

Source§

impl<T: Display> IntoR for AsDisplayVec<T>

Source§

impl<V: AtomicElement> IntoR for NamedVector<BTreeMap<String, V>>

Source§

impl<V: AtomicElement> IntoR for NamedVector<HashMap<String, V>>