Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pola-rs
GitHub Repository: pola-rs/polars
Path: blob/main/crates/polars-arrow/src/array/struct_/fmt.rs
6939 views
1
use std::fmt::{Debug, Formatter, Result, Write};
2
3
use super::super::fmt::{get_display, write_map, write_vec};
4
use super::StructArray;
5
6
pub fn write_value<W: Write>(
7
array: &StructArray,
8
index: usize,
9
null: &'static str,
10
f: &mut W,
11
) -> Result {
12
let writer = |f: &mut W, _index| {
13
for (i, (field, column)) in array.fields().iter().zip(array.values()).enumerate() {
14
if i != 0 {
15
write!(f, ", ")?;
16
}
17
let writer = get_display(column.as_ref(), null);
18
write!(f, "{}: ", field.name)?;
19
writer(f, index)?;
20
}
21
Ok(())
22
};
23
24
write_map(f, writer, None, 1, null, false)
25
}
26
27
impl Debug for StructArray {
28
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
29
let writer = |f: &mut Formatter, index| write_value(self, index, "None", f);
30
31
write!(f, "StructArray")?;
32
write_vec(f, writer, self.validity(), self.len(), "None", false)
33
}
34
}
35
36