1use std::fmt::Debug;
2
3pub use tracing;
5
6pub trait DebugUnknown {
7 fn internal_fmt(&self) -> String;
8}
9impl<T> DebugUnknown for &T {
10 fn internal_fmt(&self) -> String {
11 "<unknown>".to_owned()
12 }
13}
14pub trait DebugNormal {
15 fn internal_fmt(&self) -> String;
16}
17impl<T: Debug> DebugNormal for T {
18 fn internal_fmt(&self) -> String {
19 format!("{self:?}")
20 }
21}
22#[macro_export]
24macro_rules! debug_format_any {
25 ($e:expr) => {{
26 #[allow(unused)]
27 use $crate::internal::{DebugNormal, DebugUnknown};
28 (&$e).internal_fmt()
29 }};
30}
31pub use debug_format_any;
32
33#[cfg(test)]
34mod tests {
35 #[test]
36 fn test_debug_format_any() {
37 struct Undebuggable;
38
39 assert_eq!(debug_format_any!(1), "1");
40 assert_eq!(debug_format_any!(Undebuggable), "<unknown>");
41 }
42}