macro_rules! unwind_context_with_io {
    (
        ( $( $context:tt )* )
        $(, writer = $writer:expr )?
        $(, panic_detector = $panic_detector:expr )?
        $(, color_scheme = $color_scheme:expr )?
        $(,)?
    ) => { ... };
}
Available on crate feature std only.
Expand description

Creates UnwindContextWithIo with a given std::io::Write writer, panic detector, color scheme, and a given function or scope context.

If not specified it uses std::io::stderr as a default writer, StdPanicDetector as a default panic detector and get_default_color_scheme_if_enabled as a default color scheme. When using default values for all optional parameters, consider the use of unwind_context macro instead. See equivalent macros section below.

The returned unwind context scope guard value should be kept alive as long as unwind context is needed. If unused, the UnwindContextWithIo will immediately drop.

Passed context arguments are lazily formatted. The created wrapper takes ownership of the given arguments, so it may be necessary to use value references, clones, or pass the pre-prepared string representation. It also supports the ... placeholder to show that some values have been omitted.

For more information about context argument, see build_unwind_context_data.

§Examples

use unwind_context::unwind_context_with_io;

fn example1(foo: u32, bar: &str, secret: &str) {
    let _ctx = unwind_context_with_io!((fn(foo, bar, ...)), color_scheme = None);
    // ...
}
use unwind_context::unwind_context_with_io;

fn example2(foo: u32, bar: &str, secret: &str) {
    let _ctx = unwind_context_with_io!((fn(foo, bar, ...)), writer = ::std::io::stdout());
    // ...
}
use unwind_context::{unwind_context_with_io, AnsiColorScheme};

fn example3<W: std::io::Write, P: unwind_context::PanicDetector>(
    foo: u32,
    bar: &str,
    custom_writer: &mut W,
    custom_panic_detector: P,
    custom_color_scheme: &'static AnsiColorScheme,
) {
    let _ctx = unwind_context_with_io!(
        (fn(foo, bar)),
        writer = custom_writer,
        panic_detector = custom_panic_detector,
        color_scheme = Some(custom_color_scheme),
    );
    // ...
}

§Equivalent macros

use unwind_context::{unwind_context, unwind_context_with_io};

fn func(foo: u32, bar: &str) {
    let _ctx = unwind_context!(fn(foo, bar));
    let _ctx = unwind_context_with_io!((fn(foo, bar)));
    let _ctx = unwind_context_with_io!(
        (fn(foo, bar)),
        writer = ::std::io::stderr(),
        panic_detector = unwind_context::StdPanicDetector,
        color_scheme = unwind_context::get_default_color_scheme_if_enabled(),
    );
}