pub trait ToDebug {
fn to_debug(&self) -> String;
}
impl<T: std::fmt::Debug> ToDebug for T {
#[inline]
fn to_debug(&self) -> String {
format!("{self:?}")
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::{asserts, macro_once};
#[test]
#[allow(unused_allocation)] fn test() {
asserts! {
"1" => 1.to_debug(),
"\"1\"" => "1".to_debug(),
"'1'" => '1'.to_debug(),
"()" => ().to_debug(),
}
macro_once! {
macro testset($($e:expr $(,)?)*) {
asserts! {
$(
format!("{:?}", &$e) => $e.to_debug(),
)*
}
}
1 2 3 4 5 6 7 8 9 10,
(1, 2), [1, 2, 3],
(1, 2, (1, 2)),
"string", 'c',
("string".to_string()),
vec![1, 2, 3],
Box::new(1),
Box::new(Box::new(0)),
&[1, 2, 3]
}
}
}