Macro unwind_context::unwind_context
source · macro_rules! unwind_context { ( $( $context:tt )* ) => { ... }; }
std
only.Expand description
Creates UnwindContextWithIo
with a default writer, panic detector, color
scheme , and given function or scope context.
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.
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::unwind_context;
fn func(a: u32, b: String, c: bool) {
let _ctx = unwind_context!(fn());
let _ctx = unwind_context!(fn(a, &b, c));
let _ctx = unwind_context!(fn(a, b.clone(), c));
let _ctx = unwind_context!(fn(..., c));
let _ctx = unwind_context!(fn(a, ...));
let _ctx = unwind_context!(fn(a, ..., c));
let _ctx = 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::unwind_context;
fn func(a: u32, b: String, c: bool) {
let _ctx = unwind_context!(fn func());
let _ctx = unwind_context!(fn func(a, &b, c));
let _ctx = unwind_context!(fn func(a, b.clone(), c));
let _ctx = unwind_context!(fn func(..., c));
let _ctx = unwind_context!(fn func(a, ...));
let _ctx = unwind_context!(fn func(a, ..., c));
let _ctx = unwind_context!(fn func(a, &b, c, "step 1"));
let _ctx = unwind_context!(fn "func"());
let _ctx = unwind_context!(fn "mod1::mod2::func"());
let _ctx = unwind_context!(fn "mod1::mod2::func"(a, &b, c));
}
- Create
UnwindContextArgs
with the given scope attributes.
use unwind_context::unwind_context;
fn func(a: u32) {
let b = a.to_string();
let c = a > 100;
let _ctx = unwind_context!(a, &b, c);
let _ctx = unwind_context!(a, b.clone(), c);
let _ctx = unwind_context!(..., c);
let _ctx = unwind_context!(a, ...);
let _ctx = unwind_context!(a, ..., c);
let _ctx = unwind_context!(a, &b, c, "step 1");
}