pub struct RustConversionBuilder {
coerce_all: bool,
coerce_params: Vec<String>,
strict: bool,
match_arg_several_ok_params: Vec<String>,
}Expand description
Builder for generating Rust conversion statements from R SEXP parameters.
Handles:
- Unit types
()→ identity binding &Dots→ special wrapper with storage- Slices
&[T]→ TryFromSexp &str→ String + Borrow (for worker thread compatibility)- Scalar references → DATAPTR_RO_unchecked
- Coercion → extract R native type + TryCoerce
- Default → TryFromSexp
Fields§
§coerce_all: boolEnable coercion for all parameters
coerce_params: Vec<String>Parameter names that should use coercion
strict: boolEnable strict input conversion for lossy types
match_arg_several_ok_params: Vec<String>Parameter names with match_arg + several_ok — use match_arg_vec_from_sexp instead of TryFromSexp.
Implementations§
Source§impl RustConversionBuilder
impl RustConversionBuilder
Sourcepub fn with_coerce_all(self) -> Self
pub fn with_coerce_all(self) -> Self
Enable coercion for all parameters.
Sourcepub fn with_coerce_param(self, param_name: String) -> Self
pub fn with_coerce_param(self, param_name: String) -> Self
Add a single parameter name that should use coercion.
param_name is matched against the identifier in the function signature.
Can be called multiple times to add several parameters.
Sourcepub fn with_strict(self) -> Self
pub fn with_strict(self) -> Self
Enable strict input conversion for lossy types (i64/u64/isize/usize + Vec variants).
Sourcepub fn with_match_arg_several_ok(self, param_name: String) -> Self
pub fn with_match_arg_several_ok(self, param_name: String) -> Self
Mark a parameter as match_arg + several_ok — uses match_arg_vec_from_sexp
instead of TryFromSexp for converting STRSXP → Vec<EnumType>.
Sourcefn should_coerce(&self, param_name: &str) -> bool
fn should_coerce(&self, param_name: &str) -> bool
Check if a parameter should use coercion.
Returns true if coerce_all is set or param_name appears in the per-parameter list.
Sourcefn conversion_stmt(
&self,
try_expr: TokenStream,
error_msg: &str,
ident: &Ident,
ty: &Type,
span: Span,
) -> TokenStream
fn conversion_stmt( &self, try_expr: TokenStream, error_msg: &str, ident: &Ident, ty: &Type, span: Span, ) -> TokenStream
Generate a conversion expression that returns a tagged condition SEXP on failure.
The R wrapper inspects .val and raises a structured rust_* condition; the
return happens from inside the C wrapper body before any further conversion.
try_expr: TheResult<T, E>-producing expressionerror_msg: Human-readable error message for the failureident: The binding name for the converted valuety: The target Rust type (for theletbinding)span: Source span for error reporting
Sourcefn conversion_stmt_untyped(
&self,
try_expr: TokenStream,
error_msg: &str,
ident: &Ident,
span: Span,
) -> TokenStream
fn conversion_stmt_untyped( &self, try_expr: TokenStream, error_msg: &str, ident: &Ident, span: Span, ) -> TokenStream
Like [conversion_stmt] but without a type annotation on the binding.
Sourcepub fn build_conversion(
&self,
pat_type: &PatType,
sexp_ident: &Ident,
) -> Vec<TokenStream>
pub fn build_conversion( &self, pat_type: &PatType, sexp_ident: &Ident, ) -> Vec<TokenStream>
Generate conversion statement for a single parameter.
This is the non-split variant: owned conversions and borrow statements are concatenated into a single list, suitable for main-thread execution where everything runs in the same scope.
pat_type: the typed pattern from the function signature (e.g.,x: i32).sexp_ident: the identifier of the raw SEXP variable holding the R argument.
Returns a flat list of let binding statements that convert sexp_ident into
the Rust type declared in pat_type.
Sourcepub fn build_conversion_split(
&self,
pat_type: &PatType,
sexp_ident: &Ident,
) -> (Vec<TokenStream>, Vec<TokenStream>)
pub fn build_conversion_split( &self, pat_type: &PatType, sexp_ident: &Ident, ) -> (Vec<TokenStream>, Vec<TokenStream>)
Generate conversion statements split into two phases for worker thread execution.
For reference types like &str, we need to:
- Convert SEXP to owned type (String) – runs on the main thread before the worker closure, so the owned value can be moved into the closure.
- Borrow from the owned type (
&str) – runs inside the worker closure.
For non-reference types (scalars, Vec, etc.) everything goes into the first
phase and the second vec is empty.
pat_type: the typed pattern from the function signature (e.g.,s: &str).sexp_ident: the identifier of the raw SEXP variable holding the R argument.
Returns (owned_conversions, borrow_statements) where each element is a list
of let binding token streams.
Sourcepub fn build_conversions(
&self,
inputs: &Punctuated<FnArg, Comma>,
sexp_idents: &[Ident],
) -> Vec<TokenStream>
pub fn build_conversions( &self, inputs: &Punctuated<FnArg, Comma>, sexp_idents: &[Ident], ) -> Vec<TokenStream>
Generate conversion statements for all parameters in a function signature.
Iterates over inputs (the function’s parameter list) paired with sexp_idents
(the corresponding SEXP variable names), calling build_conversion
for each typed parameter. Receiver parameters (self) are silently skipped.
Returns a flat list of all conversion statements, in parameter order.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for RustConversionBuilder
impl RefUnwindSafe for RustConversionBuilder
impl Send for RustConversionBuilder
impl Sync for RustConversionBuilder
impl Unpin for RustConversionBuilder
impl UnsafeUnpin for RustConversionBuilder
impl UnwindSafe for RustConversionBuilder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> SizedTypeProperties for T
impl<T> SizedTypeProperties for T
Source§#[doc(hidden)]const SIZE: usize = _
#[doc(hidden)]const SIZE: usize = _
sized_type_properties)Source§#[doc(hidden)]const ALIGN: usize = _
#[doc(hidden)]const ALIGN: usize = _
sized_type_properties)Source§#[doc(hidden)]const ALIGNMENT: Alignment = _
#[doc(hidden)]const ALIGNMENT: Alignment = _
ptr_alignment_type)Source§#[doc(hidden)]const IS_ZST: bool = _
#[doc(hidden)]const IS_ZST: bool = _
sized_type_properties)Source§#[doc(hidden)]const LAYOUT: Layout = _
#[doc(hidden)]const LAYOUT: Layout = _
sized_type_properties)Source§#[doc(hidden)]const MAX_SLICE_LEN: usize = _
#[doc(hidden)]const MAX_SLICE_LEN: usize = _
sized_type_properties)[Self]. Read moreLayout§
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: 56 bytes