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
35
36
37
38
39
40
use vortex_error::VortexResult;

use crate::visitor::ArrayVisitor;
use crate::ArrayData;

#[derive(Default, Debug)]
pub struct ChildrenCollector {
    children: Vec<ArrayData>,
}

#[derive(Default, Debug)]
pub struct NamedChildrenCollector {
    children: Vec<(String, ArrayData)>,
}

impl ChildrenCollector {
    pub fn children(self) -> Vec<ArrayData> {
        self.children
    }
}

impl NamedChildrenCollector {
    pub fn children(self) -> Vec<(String, ArrayData)> {
        self.children
    }
}

impl ArrayVisitor for ChildrenCollector {
    fn visit_child(&mut self, _name: &str, array: &ArrayData) -> VortexResult<()> {
        self.children.push(array.clone());
        Ok(())
    }
}

impl ArrayVisitor for NamedChildrenCollector {
    fn visit_child(&mut self, name: &str, array: &ArrayData) -> VortexResult<()> {
        self.children.push((name.to_string(), array.clone()));
        Ok(())
    }
}