macro_rules! impl_redacted_debug {
($ty:ty) => { ... };
}Expand description
Implements release Debug by delegating to Display.
Pair this with #[cfg_attr(debug_assertions, derive(Debug))] on error types
whose fields may contain sensitive runtime detail. Do not use
#[derive(Debug)] unconditionally: in release that either conflicts with
the impl emitted here or, if this macro is omitted, leaks every field
through the derived Debug.
#[cfg_attr(debug_assertions, derive(Debug))]
struct MyError(String);
impl std::fmt::Display for MyError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str("public")
}
}
redacted_error::impl_redacted_debug!(MyError);
let err = MyError("secret".into());
let _ = format!("{err:?}");