-
Notifications
You must be signed in to change notification settings - Fork 140
Expand file tree
/
Copy pathdebug.rs
More file actions
24 lines (21 loc) · 756 Bytes
/
debug.rs
File metadata and controls
24 lines (21 loc) · 756 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: Copyright the Vortex contributors
use std::fmt::Debug;
use std::fmt::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, "]")
}
}
}