Macro custom_print::dbgwrite [−][src]
macro_rules! dbgwrite { ( $macro:path, $writer:expr, expect, $format:literal $(, $($args:tt)+)? ) => { ... }; ( $macro:path, $writer:expr, try, $format:literal $(, $($args:tt)+)? ) => { ... }; }
Expand description
Prints and returns the value of a given expression for quick and dirty debugging with the specified write macro, writer, format and error-handling policy.
The implementation of the dbgwrite
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.
If the try
policy is used, it propagates write error and
returns values wrapper into Result
.
Panics
The macro panics if writing fails and the expect
policy is used.
Examples
use core::fmt::Write; let mut string = String::new(); assert_eq!(custom_print::dbgwrite!(writeln, &mut string, expect, ":?", "first"), ("first")); assert!(string.contains("\"first\"")); assert_eq!(custom_print::dbgwrite!(writeln, &mut string, try, ":?", "second"), Ok(("second"))); assert!(string.contains("\"second\""));