Expand description
Condition macros and signal enum for the Rust→R condition pipeline.
This module provides two things:
-
RConditionenum — the internal panic payload used byerror!(),warning!(),message!(), andcondition!()macros. Caught bywith_r_unwind_protect_error_in_rbefore the generic panic→error path, then forwarded to R as a structured condition withrust_*class layering. -
AsRErrorstruct — wraps anyE: std::error::Errorand preserves the full error chain (cause/source) when converting to an R error message. Use as theErrtype inResultreturns.
§Condition macros
The four macros are the user-facing API for raising non-panic conditions from
Rust. They all require error_in_r mode (the default for #[miniextendr]
functions):
use miniextendr_api::{error, warning, message, condition};
#[miniextendr]
fn demo_error() {
error!("something went wrong: {}", 42);
}
#[miniextendr]
fn demo_warning() {
warning!("something looks suspicious");
}
#[miniextendr]
fn demo_message() {
message!("progress: {} of {}", 1, 10);
}
#[miniextendr]
fn demo_condition() {
condition!("a signallable condition");
}Optional class = extension for programmatic catching:
#[miniextendr]
fn typed_error(name: &str) {
error!(class = "my_error", "missing field: {name}");
}tryCatch(typed_error("x"), my_error = function(e) "caught!")
# [1] "caught!"§AsRError
use miniextendr_api::condition::AsRError;
#[miniextendr]
fn parse_config(path: &str) -> Result<i32, AsRError<std::io::Error>> {
let content = std::fs::read_to_string(path).map_err(AsRError)?;
Ok(content.len() as i32)
}Structs§
- AsRError
- Structured error wrapper that preserves the
std::error::Errorcause chain.
Enums§
- RCondition 👻
- Internal panic payload for structured R conditions.
Functions§
- repanic_
if_ ⚠rust_ error - Inspect a SEXP returned by a trait-ABI vtable shim and, if it is a tagged
error value, re-panic with the reconstructed
RCondition.