use std::fmt;
use crate::ArrayRef;
pub struct TreeContext {
pub(crate) ancestor_sizes: Vec<Option<u64>>,
}
impl TreeContext {
pub(crate) fn new() -> Self {
Self {
ancestor_sizes: Vec::new(),
}
}
pub fn parent_total_size(&self) -> Option<u64> {
self.ancestor_sizes.last().cloned().flatten()
}
pub(crate) fn push(&mut self, size: Option<u64>) {
self.ancestor_sizes.push(size);
}
pub(crate) fn pop(&mut self) {
self.ancestor_sizes.pop();
}
}
pub struct IndentedFormatter<'a, 'b> {
inner: &'a mut fmt::Formatter<'b>,
indent: &'a str,
}
impl<'a, 'b> IndentedFormatter<'a, 'b> {
pub(crate) fn new(f: &'a mut fmt::Formatter<'b>, indent: &'a str) -> Self {
Self { inner: f, indent }
}
pub fn parts(&mut self) -> (&str, &mut fmt::Formatter<'b>) {
(self.indent, self.inner)
}
pub fn indent(&self) -> &str {
self.indent
}
pub fn formatter(&mut self) -> &mut fmt::Formatter<'b> {
self.inner
}
}
pub trait TreeExtractor: Send + Sync {
fn write_header(
&self,
array: &ArrayRef,
ctx: &TreeContext,
f: &mut fmt::Formatter<'_>,
) -> fmt::Result {
let _ = (array, ctx, f);
Ok(())
}
fn write_details(
&self,
array: &ArrayRef,
ctx: &TreeContext,
f: &mut IndentedFormatter<'_, '_>,
) -> fmt::Result {
let _ = (array, ctx, f);
Ok(())
}
}