vortex_buffer/
debug.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
use std::fmt::{Debug, Formatter};

/// A wrapper around a slice that truncates the debug output if it is too long.
pub(crate) struct TruncatedDebug<'a, T>(pub(crate) &'a [T]);

impl<T: Debug> Debug for TruncatedDebug<'_, T> {
    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
        const TRUNC_SIZE: usize = 16;
        if self.0.len() <= TRUNC_SIZE {
            write!(f, "{:?}", self.0)
        } else {
            write!(f, "[")?;
            for elem in self.0.iter().take(TRUNC_SIZE) {
                write!(f, "{:?}, ", *elem)?;
            }
            write!(f, "...")?;
            write!(f, "]")
        }
    }
}