Skip to main content

Module coerce

Module coerce 

Source
Expand description

Type coercion traits for converting Rust types to R native types.

R has a fixed set of native scalar types:

  • i32 (INTSXP) - 32-bit signed integer
  • f64 (REALSXP) - 64-bit floating point
  • RLogical (LGLSXP) - logical (TRUE/FALSE/NA)
  • u8 (RAWSXP) - raw bytes
  • Rcomplex (CPLXSXP) - complex numbers

ยงTraits

  • Coerce<R> - infallible coercion (identity, widening)
  • TryCoerce<R> - fallible coercion (narrowing, overflow-possible)

ยงExamples

โ“˜
use miniextendr_api::coerce::Coerce;

// Scalar coercion
let x: i32 = 42i8.coerce();

// Element-wise slice coercion
let slice: &[i8] = &[1, 2, 3];
let vec: Vec<i32> = slice.coerce();

Macrosยง

impl_identity ๐Ÿ”’
impl_nonzero_from_self ๐Ÿ”’
impl_try_i8 ๐Ÿ”’
impl_try_i16 ๐Ÿ”’
impl_try_i32 ๐Ÿ”’
impl_try_u8 ๐Ÿ”’
impl_try_u16 ๐Ÿ”’
impl_tuple_coerce ๐Ÿ”’
Macro to implement element-wise Coerce for tuples.

Structsยง

Coerced
Wrapper for values coerced from an R native type during conversion.

Enumsยง

CoerceError
Error type for coercion failures.
LogicalCoerceError
Error type for logical coercion failures.

Traitsยง

Coerce
Infallible coercion from Self to type R.
TryCoerce
Fallible coercion from Self to type R.