macro_rules! debug_unwind_context {
    ( $( $context:tt )* ) => { ... };
}
Available on crate feature std only.
Expand description

Creates UnwindContextWithIo with a default writer, panic detector, color scheme , and given function or scope context in debug builds only.

It uses std::io::stderr writer, StdPanicDetector panic detector, and a color scheme determined by the get_default_color_scheme_if_enabled function. If you want to customize a writer, a panic detector, or a color scheme, use unwind_context_with_io or unwind_context_with_fmt.

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. Note that the colorization is disabled by default and can be enabled either by the [set_colors_enabled] or [enable_colors_if_supported`] functions.

Passed 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.

An optimized build will generate () unless -C debug-assertions is passed to the compiler. This makes this macro no-op with the default release profile.

There are three forms of this macro:

  • Create UnwindContextFunc with an automatically determined function name and the given attributes as function attributes. The arguments do not have to be the real function arguments.
use unwind_context::debug_unwind_context;

fn func(a: u32, b: String, c: bool) {
    let _ctx = debug_unwind_context!(fn());
    let _ctx = debug_unwind_context!(fn(a, &b, c));
    let _ctx = debug_unwind_context!(fn(a, b.clone(), c));
    let _ctx = debug_unwind_context!(fn(..., c));
    let _ctx = debug_unwind_context!(fn(a, ...));
    let _ctx = debug_unwind_context!(fn(a, ..., c));
    let _ctx = debug_unwind_context!(fn(a, &b, c, "step 1"));
    // ...
}
  • Create UnwindContextFunc with a specific function names and the given attributes as function attributes. Note that only ident-like function names are supported is unquoted. Path names should be enclosed in quotes. The arguments do not have to be the real function arguments.
use unwind_context::debug_unwind_context;

fn func(a: u32, b: String, c: bool) {
    let _ctx = debug_unwind_context!(fn func());
    let _ctx = debug_unwind_context!(fn func(a, &b, c));
    let _ctx = debug_unwind_context!(fn func(a, b.clone(), c));
    let _ctx = debug_unwind_context!(fn func(..., c));
    let _ctx = debug_unwind_context!(fn func(a, ...));
    let _ctx = debug_unwind_context!(fn func(a, ..., c));
    let _ctx = debug_unwind_context!(fn func(a, &b, c, "step 1"));
    let _ctx = debug_unwind_context!(fn "func"());
    let _ctx = debug_unwind_context!(fn "mod1::mod2::func"());
    let _ctx = debug_unwind_context!(fn "mod1::mod2::func"(a, &b, c));
    // ...
}
use unwind_context::debug_unwind_context;

fn func(a: u32) {
    let b = a.to_string();
    let c = a > 100;
    let _ctx = debug_unwind_context!(a, &b, c);
    let _ctx = debug_unwind_context!(a, b.clone(), c);
    let _ctx = debug_unwind_context!(..., c);
    let _ctx = debug_unwind_context!(a, ...);
    let _ctx = debug_unwind_context!(a, ..., c);
    let _ctx = debug_unwind_context!(a, &b, c, "step 1");
    // ...
}