Macro custom_print::define_try_dbg
source · macro_rules! define_try_dbg { ( $( #[$meta:meta] )* $name:ident, $($args:tt)* ) => { ... }; }
Expand description
Defines try_dbg
macro that prints and returns the value
of a given expression wrapped in for quick and dirty debugging
or return an error if write failed.
The implementation of the generated dbg
-like macro
is based on std::dbg
macro implementation,
but the exact output printed by std::dbg
should not be relied upon and is subject to future changes.
The first argument specifies the generated macro name.
The writer itself is specified by the rest arguments with the define_writer
macros.
Use define_dbg
if you need to define a non-fallible dbg macros.
Examples
let mut string = String::new();
custom_print::define_try_dbg!(try_dbg, concat, |value: &str| string += value);
assert_eq!(try_dbg!("value"), Ok("value"));
assert!(string.contains("\"value\""));