Skip to content

Commit a04662a

Browse files
committed
Share tree display extractor utility
Signed-off-by: Joe Isaacs <joe.isaacs@live.co.uk>
1 parent cf4255f commit a04662a

10 files changed

Lines changed: 36 additions & 46 deletions

File tree

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
// SPDX-License-Identifier: Apache-2.0
22
// SPDX-FileCopyrightText: Copyright the Vortex contributors
33

4-
use std::fmt;
5-
64
pub use vortex_utils::tree::IndentedFormatter;
75
use vortex_utils::tree::TreeDisplayContext;
6+
pub use vortex_utils::tree::TreeDisplayExtractor as TreeExtractor;
87

98
use crate::ArrayRef;
109
use crate::arrays::Chunked;
@@ -44,37 +43,3 @@ impl TreeDisplayContext<ArrayRef> for TreeContext {
4443
self.ancestor_sizes.pop();
4544
}
4645
}
47-
48-
/// Trait for contributing display information to tree nodes.
49-
///
50-
/// Each extractor represents one "dimension" of display (e.g., nbytes, stats, metadata, buffers).
51-
/// Extractors are composable: you can combine any number of them via [`TreeDisplay::with`].
52-
///
53-
/// [`TreeDisplay::with`]: super::TreeDisplay::with
54-
pub trait TreeExtractor: Send + Sync {
55-
/// Write header annotations (space-prefixed) to the formatter.
56-
fn write_header(
57-
&self,
58-
array: &ArrayRef,
59-
ctx: &TreeContext,
60-
f: &mut fmt::Formatter<'_>,
61-
) -> fmt::Result {
62-
let _ = (array, ctx, f);
63-
Ok(())
64-
}
65-
66-
/// Write detail lines below the header.
67-
///
68-
/// Content written through `f` is automatically indented. Use
69-
/// [`f.formatter()`](IndentedFormatter::formatter) to access the underlying
70-
/// [`fmt::Formatter`] for formatting flags.
71-
fn write_details(
72-
&self,
73-
array: &ArrayRef,
74-
ctx: &TreeContext,
75-
f: &mut IndentedFormatter<'_, '_>,
76-
) -> fmt::Result {
77-
let _ = (array, ctx, f);
78-
Ok(())
79-
}
80-
}

vortex-array/src/display/extractors/buffer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ pub struct BufferExtractor {
1717
pub show_percent: bool,
1818
}
1919

20-
impl TreeExtractor for BufferExtractor {
20+
impl TreeExtractor<ArrayRef, TreeContext> for BufferExtractor {
2121
fn write_details(
2222
&self,
2323
array: &ArrayRef,

vortex-array/src/display/extractors/encoding_summary.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ impl EncodingSummaryExtractor {
2323
}
2424
}
2525

26-
impl TreeExtractor for EncodingSummaryExtractor {
26+
impl TreeExtractor<ArrayRef, TreeContext> for EncodingSummaryExtractor {
2727
fn write_header(
2828
&self,
2929
array: &ArrayRef,

vortex-array/src/display/extractors/metadata.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use crate::display::extractor::TreeExtractor;
1111
/// Extractor that adds a `metadata: ...` detail line.
1212
pub struct MetadataExtractor;
1313

14-
impl TreeExtractor for MetadataExtractor {
14+
impl TreeExtractor<ArrayRef, TreeContext> for MetadataExtractor {
1515
fn write_details(
1616
&self,
1717
array: &ArrayRef,

vortex-array/src/display/extractors/nbytes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use crate::display::extractor::TreeExtractor;
1313
/// Extractor that adds `nbytes=X (Y%)` to the header line.
1414
pub struct NbytesExtractor;
1515

16-
impl TreeExtractor for NbytesExtractor {
16+
impl TreeExtractor<ArrayRef, TreeContext> for NbytesExtractor {
1717
fn write_header(
1818
&self,
1919
array: &ArrayRef,

vortex-array/src/display/extractors/stats.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ impl fmt::Display for StatsDisplay<'_> {
116116
/// Extractor that adds stats annotations (e.g. `[nulls=3, min=5]`) to the header line.
117117
pub struct StatsExtractor;
118118

119-
impl TreeExtractor for StatsExtractor {
119+
impl TreeExtractor<ArrayRef, TreeContext> for StatsExtractor {
120120
fn write_header(
121121
&self,
122122
array: &ArrayRef,

vortex-array/src/display/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,7 @@ impl ArrayRef {
556556
metadata,
557557
stats,
558558
} => {
559-
let extractors: [(bool, Box<dyn TreeExtractor>); 5] = [
559+
let extractors: [(bool, Box<dyn TreeExtractor<ArrayRef, TreeContext>>); 5] = [
560560
(true, Box::new(EncodingSummaryExtractor)),
561561
(*stats, Box::new(NbytesExtractor)),
562562
(*stats, Box::new(StatsExtractor)),

vortex-array/src/display/tree_display.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ use crate::display::extractors::StatsExtractor;
3939
/// ```
4040
pub struct TreeDisplay {
4141
array: ArrayRef,
42-
extractors: Vec<Box<dyn TreeExtractor>>,
42+
extractors: Vec<Box<dyn TreeExtractor<ArrayRef, TreeContext>>>,
4343
}
4444

4545
impl TreeDisplay {
@@ -66,13 +66,13 @@ impl TreeDisplay {
6666
}
6767

6868
/// Add an extractor to the display pipeline.
69-
pub fn with<E: TreeExtractor + 'static>(mut self, extractor: E) -> Self {
69+
pub fn with<E: TreeExtractor<ArrayRef, TreeContext> + 'static>(mut self, extractor: E) -> Self {
7070
self.extractors.push(Box::new(extractor));
7171
self
7272
}
7373

7474
/// Add a pre-boxed extractor to the display pipeline.
75-
pub fn with_boxed(mut self, extractor: Box<dyn TreeExtractor>) -> Self {
75+
pub fn with_boxed(mut self, extractor: Box<dyn TreeExtractor<ArrayRef, TreeContext>>) -> Self {
7676
self.extractors.push(extractor);
7777
self
7878
}

vortex-btrblocks/tests/golden.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ const N: usize = 16_384;
6565
/// [`NbytesExtractor`]: vortex_array::display::NbytesExtractor
6666
struct ExactNbytesExtractor;
6767

68-
impl TreeExtractor for ExactNbytesExtractor {
68+
impl TreeExtractor<ArrayRef, TreeContext> for ExactNbytesExtractor {
6969
fn write_header(
7070
&self,
7171
array: &ArrayRef,

vortex-utils/src/tree.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,31 @@ impl<'a, 'b> IndentedFormatter<'a, 'b> {
7474
}
7575
}
7676

77+
/// Contributes one composable dimension of information to tree nodes.
78+
pub trait TreeDisplayExtractor<N: ?Sized, C: TreeDisplayContext<N>>: Send + Sync {
79+
/// Write space-prefixed annotations on the node's header line.
80+
fn write_header(
81+
&self,
82+
node: &N,
83+
context: &C,
84+
formatter: &mut fmt::Formatter<'_>,
85+
) -> fmt::Result {
86+
_ = (node, context, formatter);
87+
Ok(())
88+
}
89+
90+
/// Write detail lines beneath the node's header.
91+
fn write_details(
92+
&self,
93+
node: &N,
94+
context: &C,
95+
formatter: &mut IndentedFormatter<'_, '_>,
96+
) -> fmt::Result {
97+
_ = (node, context, formatter);
98+
Ok(())
99+
}
100+
}
101+
77102
/// Adapts a domain-specific node and traversal context to the shared tree renderers.
78103
pub trait TreeDisplayAdapter {
79104
/// Node type traversed by this adapter.

0 commit comments

Comments
 (0)