Skip to content

Commit 81234f5

Browse files
authored
fix: TreeDisplayWrapper is private (#2433)
1 parent d4e56a6 commit 81234f5

File tree

4 files changed

+43
-18
lines changed

4 files changed

+43
-18
lines changed

vortex-array/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ pub mod stats;
3939
pub mod stream;
4040
#[cfg(feature = "test-harness")]
4141
pub mod test_harness;
42-
pub mod tree;
42+
mod tree;
4343
pub mod validity;
4444
pub mod variants;
4545
pub mod visitor;

vortex-array/src/tree.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ impl Array {
1616
}
1717
}
1818

19-
pub struct TreeDisplayWrapper<'a>(pub &'a Array);
19+
struct TreeDisplayWrapper<'a>(&'a Array);
2020

2121
impl fmt::Display for TreeDisplayWrapper<'_> {
2222
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
@@ -34,23 +34,20 @@ pub struct TreeFormatter<'a, 'b: 'a> {
3434
total_size: Option<usize>,
3535
}
3636

37-
/// TODO(ngates): I think we want to go back to the old explicit style. It gives arrays more
38-
/// control over how their metadata etc is displayed.
3937
impl<'a, 'b: 'a> ArrayVisitor for TreeFormatter<'a, 'b> {
4038
fn visit_child(&mut self, name: &str, array: &Array) -> VortexResult<()> {
4139
let nbytes = array.nbytes();
4240
let total_size = self.total_size.unwrap_or(nbytes);
4341
writeln!(
44-
self.fmt,
45-
"{}{}: {} nbytes={} ({:.2}%)",
46-
self.indent,
42+
self,
43+
"{}: {} nbytes={} ({:.2}%)",
4744
name,
4845
array,
4946
format_size(nbytes, DECIMAL),
5047
100f64 * nbytes as f64 / total_size as f64
5148
)?;
5249
self.indent(|i| {
53-
write!(i.fmt, "{}metadata: ", i.indent)?;
50+
write!(i, "metadata: ")?;
5451
array.vtable().display_metadata(array, i.fmt)?;
5552
writeln!(i.fmt)
5653
})?;
@@ -72,9 +69,8 @@ impl<'a, 'b: 'a> ArrayVisitor for TreeFormatter<'a, 'b> {
7269

7370
fn visit_buffer(&mut self, buffer: &ByteBuffer) -> VortexResult<()> {
7471
Ok(writeln!(
75-
self.fmt,
76-
"{}buffer (align={}): {}",
77-
self.indent,
72+
self,
73+
"buffer (align={}): {}",
7874
buffer.alignment(),
7975
format_size(buffer.len(), DECIMAL)
8076
)?)
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
use std::fmt;
2+
3+
pub struct IndentFormatter<'a, 'b: 'a> {
4+
fmt: &'a mut fmt::Formatter<'b>,
5+
indent: String,
6+
}
7+
8+
impl<'a, 'b: 'a> IndentFormatter<'a, 'b> {
9+
pub fn new(fmt: &'a mut fmt::Formatter<'b>, indent: String) -> Self {
10+
IndentFormatter { fmt, indent }
11+
}
12+
13+
pub fn indent<F>(&mut self, indented: F) -> fmt::Result
14+
where
15+
F: FnOnce(&mut IndentFormatter) -> fmt::Result,
16+
{
17+
let original_ident = self.indent.clone();
18+
self.indent += " ";
19+
let res = indented(self);
20+
self.indent = original_ident;
21+
res
22+
}
23+
24+
pub fn write_fmt(&mut self, fmt: fmt::Arguments<'_>) -> fmt::Result {
25+
write!(self.fmt, "{}{}", self.indent, fmt)
26+
}
27+
}

vortex-sampling-compressor/src/compressors/mod.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
use std::any::Any;
2-
use std::fmt::{Debug, Display, Formatter};
2+
use std::fmt;
3+
use std::fmt::{Debug, Display};
34
use std::hash::{Hash, Hasher};
45
use std::sync::Arc;
56

67
use itertools::{EitherOrBoth, Itertools};
78
use vortex_array::aliases::hash_set::HashSet;
8-
use vortex_array::tree::TreeFormatter;
99
use vortex_array::{Array, EncodingId};
1010
use vortex_error::{vortex_panic, VortexExpect, VortexResult};
1111

12+
use crate::compressors::formatter::IndentFormatter;
1213
use crate::SamplingCompressor;
1314

1415
pub mod alp;
@@ -20,6 +21,7 @@ pub mod date_time_parts;
2021
pub mod delta;
2122
pub mod dict;
2223
pub mod r#for;
24+
mod formatter;
2325
pub mod fsst;
2426
pub mod list;
2527
pub mod runend;
@@ -67,7 +69,7 @@ pub struct CompressionTree<'a> {
6769
}
6870

6971
impl Debug for CompressionTree<'_> {
70-
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
72+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
7173
write!(f, "{self}")
7274
}
7375
}
@@ -81,17 +83,17 @@ pub trait EncoderMetadata: 'static + Send + Sync {
8183
}
8284

8385
impl Display for CompressionTree<'_> {
84-
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
85-
let mut fmt = TreeFormatter::new(f, "".to_string());
86+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
87+
let mut fmt = IndentFormatter::new(f, "".to_string());
8688
visit_child("root", Some(self), &mut fmt)
8789
}
8890
}
8991

9092
fn visit_child(
9193
name: &str,
9294
child: Option<&CompressionTree>,
93-
fmt: &mut TreeFormatter,
94-
) -> std::fmt::Result {
95+
fmt: &mut IndentFormatter,
96+
) -> fmt::Result {
9597
fmt.indent(|f| {
9698
if let Some(child) = child {
9799
writeln!(f, "{name}: {}", child.compressor.id())?;

0 commit comments

Comments
 (0)