macro_rules! condition {
(class = $class:expr, data = $data:tt, $($arg:tt)*) => { ... };
(data = $data:tt, $($arg:tt)*) => { ... };
(class = $class:expr, $($arg:tt)*) => { ... };
($($arg:tt)*) => { ... };
}Expand description
Signal a generic R condition from Rust with rust_condition class layering.
Rides the tagged-condition transport that every #[miniextendr] function uses.
Unlike error!, a bare condition is a silent no-op if there is no handler.
The raised condition has class c("rust_condition", "simpleCondition", "condition").
An optional class = "name" form prepends a custom class. An optional
data = ... form (after class, before the message) attaches named fields
readable as c$<name> in handlers — same grammar and supported value types
as crate::error! (see there for details).
§See also
crate::error!/crate::warning!/crate::message!— louder condition kinds. Pickcondition!when “no handler = silent” is the right default (progress events, structured logging hooks).std::panic!— escape hatch when the failure cannot be ignored.crate::error_value— tagged-SEXP transport rationale.
Name-collision note. Because pub mod condition exists at the crate
root, use miniextendr_api::condition imports the module rather than this
macro. Invoke via miniextendr_api::condition!(...) (fully qualified) or
via mx::condition!(...) after use miniextendr_api as mx;.
§Example
use miniextendr_api::condition;
#[miniextendr]
fn signal_progress(n: i32) {
condition!(class = "my_progress", "processed {n} items");
}withCallingHandlers(
signal_progress(42L),
my_progress = function(c) cat("progress:", conditionMessage(c), "\n")
)
# progress: processed 42 items