Skip to main content

capture

Function capture 

Source
pub fn capture<R>(f: impl FnOnce() -> R) -> (R, String)
Expand description

Run f, collecting what it prints through print_run instead of writing it to stdout (#2998): bynk test asks a project for its discovery document in-process, where it used to read a child’s stdout.

Re-entrant and panic-safe: a drop guard restores whatever capture was in force before (none, or an outer capture’s buffer), also when f unwinds, so a panic cannot leave later output swallowed. The text printed inside an inner capture goes to the inner result only, not to the outer one.