Skip to main content

Module result

Module result 

Source
Expand description

Result<T, E> conversions to R.

Used by #[miniextendr(unwrap_in_r)] to pass Results to R as values (Err becomes list(error = ...)), instead of unwrapping in Rust. Also provides NullOnErr for Result<T, ()> → NULL-on-error semantics.

§Tradeoff

The two impls in this module have different gating conditions:

  • IntoR for Result<T, E: Display> (the list(error = ...) shape) fires only under #[miniextendr(unwrap_in_r)] (Result-as-value). Without that attribute, a Result<T, E> return acts as an error boundary: Err(e) panics with Debug-formatted e, the framework’s tagged-condition transport carries it to R, and the wrapper raises a classed rust_* condition. Failure mode of opting into unwrap_in_r without telling R callers: they suddenly need to check $error on every return value instead of using tryCatch.
  • IntoR for Result<T, NullOnErr> fires whenever the error type is (), independent of unwrap_in_r: the macro rewrites Result<T, ()> to Result<T, NullOnErr> before the unwrap_in_r check, so Err(()) returns NULL to R in both modes. A unit error is a deliberate “no value” sentinel, not a Rust failure — it never raises an R error.

Structs§

NullOnErr
Marker type for Result<T, ()> that converts Err(()) to NULL.