Skip to main content

CoercionMapping

Enum CoercionMapping 

Source
pub(crate) enum CoercionMapping {
    Scalar {
        r_native: TokenStream,
        target: TokenStream,
    },
    Vec {
        r_native_elem: TokenStream,
        target_elem: TokenStream,
    },
}
Expand description

Result of coercion analysis for a type. Contains the R native type to extract from SEXP and the target type to coerce to.

Variants§

§

Scalar

Scalar coercion: extract R native type, coerce to target.

Fields

§r_native: TokenStream

The R-native scalar type to extract from the SEXP (e.g., i32 for R integers, f64 for R reals). This is the type that R stores internally.

§target: TokenStream

The Rust target type to coerce into (e.g., u16, bool, f32).

§

Vec

Vec coercion: extract R native slice, coerce element-wise to Vec<target>.

Fields

§r_native_elem: TokenStream

The R-native element type of the source slice (e.g., i32 for integer vectors, f64 for real vectors).

§target_elem: TokenStream

The Rust target element type for the resulting Vec (e.g., u16, bool, f32).

Implementations§

Source§

impl CoercionMapping

Source

pub(crate) fn from_type(ty: &Type) -> Option<Self>

Determines the coercion mapping for a Rust type, if it needs coercion from an R-native type.

Returns None if the type is already R-native (i32, f64, String, etc.) or is not a recognized coercible type.

§Recognized coercions
  • Scalar integer-like (u16, i16, i8, u32, u64, i64, isize, usize): coerced from i32 (R’s native integer type).
  • Scalar bool: coerced from i32 (R’s logical vectors use i32 internally).
  • Scalar f32: coerced from f64 (R’s native real type).
  • Vec<T> variants: element-wise coercion from the corresponding R-native slice type.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> SizedTypeProperties for T

Source§

#[doc(hidden)]
const SIZE: usize = _

🔬This is a nightly-only experimental API. (sized_type_properties)
Source§

#[doc(hidden)]
const ALIGN: usize = _

🔬This is a nightly-only experimental API. (sized_type_properties)
Source§

#[doc(hidden)]
const ALIGNMENT: Alignment = _

🔬This is a nightly-only experimental API. (ptr_alignment_type)
Source§

#[doc(hidden)]
const IS_ZST: bool = _

🔬This is a nightly-only experimental API. (sized_type_properties)
true if this type requires no storage. false if its size is greater than zero. Read more
Source§

#[doc(hidden)]
const LAYOUT: Layout = _

🔬This is a nightly-only experimental API. (sized_type_properties)
Source§

#[doc(hidden)]
const MAX_SLICE_LEN: usize = _

🔬This is a nightly-only experimental API. (sized_type_properties)
The largest safe length for a [Self]. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.

Layout§

Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...) attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.

Size: 72 bytes

Size for each variant:

  • Scalar: 64 bytes
  • Vec: 64 bytes