macro_rules! defer_warning {
($($t:tt)*) => { ... };
}Expand description
Queue an R warning with rust_warning class layering and return normally;
the surrounding guarded call or callback signals it after its value is
computed.
Same grammar as crate::warning!: optional call = none (no call, like
R’s warning(..., call. = FALSE)), optional class = … (one class or a
vector, most specific first), optional data = … (a pair, a bracketed
list of pairs, or { name = value } sugar), then the format! message.
For a typed payload use crate::defer_warning() with a
#[derive(RCondition)] type (#[condition(call = none)] on the type
or a variant drops the call there).
A later Err does not cancel this warning. To avoid warnings on failure,
queue after the last fallible step; see warning placement.
ⓘ
use miniextendr_api::defer_warning;
#[miniextendr]
fn parse_all(xs: Vec<String>) -> Vec<i32> {
let (ok, bad): (Vec<_>, Vec<_>) = xs.iter().map(|s| s.parse::<i32>()).partition(Result::is_ok);
if !bad.is_empty() {
defer_warning!(class = "pkg_unparsed", data = ("n", bad.len() as i32), "{} values could not be parsed", bad.len());
}
ok.into_iter().map(Result::unwrap).collect()
}