custom_debug/
custom_debug.rs1use std::{fmt, marker::PhantomData};
2
3use fmt_ext::{debug::*, DebugExt};
4
5struct SliceWithLenDebug<T>(PhantomData<T>);
7
8impl<T> CustomDebug for SliceWithLenDebug<T>
10where
11 T: fmt::Debug,
12{
13 type Target = [T];
14
15 fn fmt_target(target: &Self::Target, f: &mut fmt::Formatter<'_>) -> fmt::Result {
16 write!(f, "Slice {{ len: {}, items: {:?} }}", target.len(), target)
17 }
18}
19
20impl<T> AttachDebug<SliceWithLenDebug<T>> for [T] {}
22
23fn main() {
25 let numbers = [0, 1, 2, 3];
26 println!("{:?}", numbers.debug());
27
28 let strings = vec!["I", "am", "a", "custom", "debug"];
29 println!("{:?}", strings.debug());
30}