Skip to main content

conversion_condition_value

Function conversion_condition_value 

Source
pub unsafe fn conversion_condition_value(
    prefix: &str,
    param: &str,
    rust_type: Option<&str>,
    crate_class: &[&str],
    parts: ErrParts,
    arg_message: Option<String>,
    call: Option<SEXP>,
) -> SEXP
Expand description

Build the tagged value for an argument that failed its Rust-side conversion: kind = "conversion", the parts probed off the error by crate::__mx_conversion_err_parts! (class, message and data from an RConditionData impl, the R-worded reason for a built-in conversion error, else the Display text), with prefix before the message ('x' must be a single integer, or invalid 'x' argument when the macro has no R-facing expectation for the type), the crate’s conversion_error_class (crate_class, emitted by the macro from [package.metadata.miniextendr]) after the error’s own classes, the parameter’s R name as e$param and the Rust type as e$rust_type. arg_message, when the error words the whole argument error itself (crate::__mx_conversion_arg_message!: a match_arg choice error, in the words of the R-side match_arg check, #1767), is the message instead of <prefix>: <reason>. See crate::condition::conversion_err_parts for how they combine.

The R-side argument checks raise the same condition from R (.miniextendr_arg_error, #1591), so a handler for the crate class, or for rust_error, sees every argument error whichever side caught it.

§Safety

Same contract as make_rust_condition_value_with_data: R main thread, valid allocation context. Every generated conversion Err arm runs inside the wrapper’s with_r_unwind_protect closure, which satisfies it.