Skip to main content

vortex_array/display/extractors/
encoding_summary.rs

1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright the Vortex contributors
3
4use std::fmt;
5
6use crate::ArrayRef;
7use crate::display::extractor::TreeContext;
8use crate::display::extractor::TreeExtractor;
9
10/// Extractor that adds the encoding summary (e.g. `vortex.primitive(i16, len=5)`) to the header.
11pub struct EncodingSummaryExtractor;
12
13impl EncodingSummaryExtractor {
14    /// Write the encoding summary for an array directly to a formatter.
15    pub fn write(array: &ArrayRef, f: &mut fmt::Formatter<'_>) -> fmt::Result {
16        write!(
17            f,
18            "{}({}, len={})",
19            array.encoding_id(),
20            array.dtype(),
21            array.len()
22        )
23    }
24}
25
26impl TreeExtractor for EncodingSummaryExtractor {
27    fn write_header(
28        &self,
29        array: &ArrayRef,
30        _ctx: &TreeContext,
31        f: &mut fmt::Formatter<'_>,
32    ) -> fmt::Result {
33        write!(f, " ")?;
34        Self::write(array, f)
35    }
36}