uqa_sql/plan/scalar/owned/
iteration.rs1use super::OwnedScalarExpr;
8
9pub struct OwnedScalarChildren {
11 parent: Option<OwnedScalarExpr>,
12 next: usize,
13 end: usize,
14}
15
16impl OwnedScalarExpr {
17 pub fn into_children(self) -> OwnedScalarChildren {
19 let end = self.child_count();
20 OwnedScalarChildren {
21 parent: (end != 0).then_some(self),
22 next: 0,
23 end,
24 }
25 }
26}
27
28impl Iterator for OwnedScalarChildren {
29 type Item = OwnedScalarExpr;
30
31 fn next(&mut self) -> Option<Self::Item> {
32 let parent = self.parent.as_mut()?;
33 let child = parent.take_child(self.next);
34 self.next += 1;
35 if self.next == self.end {
36 self.parent = None;
37 }
38 Some(child)
39 }
40
41 fn size_hint(&self) -> (usize, Option<usize>) {
42 let remaining = self.end - self.next;
43 (remaining, Some(remaining))
44 }
45}
46
47impl ExactSizeIterator for OwnedScalarChildren {}
48impl std::iter::FusedIterator for OwnedScalarChildren {}