macro_rules! debug_unwind_context_with_io { ( $( $tokens:tt )* ) => { ... }; }
std
only.Expand description
Creates UnwindContextWithIo
with a given std::io::Write
writer,
panic detector, color scheme, and a given function or scope context in debug
builds only.
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 debug_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.
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.
For more information about macro arguments, see unwind_context_with_io
.
For more information about context argument, see
build_unwind_context_data
.
§Examples
use unwind_context::debug_unwind_context_with_io;
fn example1(foo: u32, bar: &str, secret: &str) {
let _ctx = debug_unwind_context_with_io!((fn(foo, bar, ...)), color_scheme = None);
// ...
}
use unwind_context::debug_unwind_context_with_io;
fn example2(foo: u32, bar: &str, secret: &str) {
let _ctx = debug_unwind_context_with_io!((fn(foo, bar, ...)), writer = ::std::io::stdout());
// ...
}
use unwind_context::{debug_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 = debug_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::{debug_unwind_context, debug_unwind_context_with_io};
fn func(foo: u32, bar: &str) {
debug_unwind_context!(fn(foo, bar));
debug_unwind_context_with_io!((fn(foo, bar)));
debug_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(),
);
}