Skip to main content

with_sink

Function with_sink 

Source
pub fn with_sink<R>(sink: Rc<dyn Sink>, f: impl FnOnce() -> R) -> R
Expand description

Install sink for the duration of f, then restore the previous sink.

Pass sink by value (typically Rc::new(RecordingSink::new()) or a clone of an existing Rc); the caller can keep their own Rc to read recorded events after the scope ends.

Panics inside f propagate; the previous sink is restored via Drop of an internal guard. Recursive emission inside Sink::record is undefined behaviour: do not call emit from inside a sink.