pub fn capture<T>(f: impl FnOnce() -> T) -> (T, Vec<RCondition>)Expand description
Run f and return the conditions it queued, oldest first, instead of
signalling them when the guarded call returns.
For code that queues diagnostics a caller already has: replaying the
steps that built a saved object repeats warnings the object recorded.
capture(f).0 discards them; each RCondition can also be inspected,
queued again with RCondition::defer or raised with
RCondition::raise.
ⓘ
use miniextendr_api::deferred_condition::capture;
let (rebuilt, warnings) = capture(|| rebuild(&snapshot));
debug_assert_eq!(warnings.len(), snapshot.warnings.len());- Conditions queued before the block, or by enclosing calls, stay queued.
- Conditions a nested
#[miniextendr]call queued were signalled when that call returned, as always. - If
funwinds (error!,Errthrough a nested raise, an R error), the block’s conditions stay queued and follow the usual rules: a Rust failure signals them, an R-origin error discards them. To keep them on failure too, catch the failure inside the block:capture(|| catch_condition(|| rebuild(&snapshot)))(seecatch_condition). - Where deferred conditions are suppressed (finalizers, see the module docs), nothing is queued and the vector is empty.