unthbuf/
fmt.rs

1//! Formatting for [`UnthBuf`]
2use super::{UnthBuf, CellLayout};
3
4impl<CL: CellLayout> core::fmt::Debug for UnthBuf<CL> {
5    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
6        // let max: Box<dyn std::fmt::Debug> = match ALIGNED {
7        //     true => Box::new(self.aligned_location_of(self.capacity-1)),
8        //     false => Box::new(self.unaligned_location_of(self.capacity-1))
9        // };
10        
11        f.debug_struct("UnthBuf")
12            .field("layout", &std::any::type_name::<CL>())
13            .field("capacity", &self.capacity)
14            .field("data_len", &self.data.len())
15            .field("bits", &self.bits)
16            .field("mask", &self.mask)
17            //.field("data", &self.data)
18            .finish()
19    }
20}
21
22impl<CL: CellLayout + 'static> core::fmt::Display for UnthBuf<CL> {
23    /// Prints the [`UnthBuf`] as a list of numbers, with the bit-size and capacity at the start...
24    /// 
25    /// ...thus taking the form: `[uBITS; CAPACITY; ELEMENT, ... ELEMENT]`
26    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
27        write!(f, "[")?;
28        write!(f, "u{}", self.bits)?;
29        write!(f, "; ")?;
30        write!(f, "{}", self.capacity)?;
31        write!(f, "; ")?;
32        let mut comma = false;
33        for element in self {
34            if comma {
35                write!(f, ", {element}")?;
36            } else {
37                write!(f, "{element}")?;
38                comma = true;
39            }
40        }
41        write!(f, "]")
42    }
43}