polars_arrow/array/struct_/
fmt.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
use std::fmt::{Debug, Formatter, Result, Write};

use super::super::fmt::{get_display, write_map, write_vec};
use super::StructArray;

pub fn write_value<W: Write>(
    array: &StructArray,
    index: usize,
    null: &'static str,
    f: &mut W,
) -> Result {
    let writer = |f: &mut W, _index| {
        for (i, (field, column)) in array.fields().iter().zip(array.values()).enumerate() {
            if i != 0 {
                write!(f, ", ")?;
            }
            let writer = get_display(column.as_ref(), null);
            write!(f, "{}: ", field.name)?;
            writer(f, index)?;
        }
        Ok(())
    };

    write_map(f, writer, None, 1, null, false)
}

impl Debug for StructArray {
    fn fmt(&self, f: &mut Formatter<'_>) -> Result {
        let writer = |f: &mut Formatter, index| write_value(self, index, "None", f);

        write!(f, "StructArray")?;
        write_vec(f, writer, self.validity(), self.len(), "None", false)
    }
}