Subviews over `self` corresponding to the children of the expression, in reverse order. These views should disjointly cover the same interval as `self`, except for the last element which corresponds to the expression itself. The number of produced items should exactly match the number of children, which need not be provided as an argument. This relies on the well-formedness of the view, which sh
(&self)
| 218 | /// be provided as an argument. This relies on the well-formedness of the view, which should |
| 219 | /// exhaust itself just as it enumerates its last (the first) child view. |
| 220 | pub fn children_rev(&self) -> impl Iterator<Item = DerivedView<'a>> + 'a { |
| 221 | // This logic is copy/paste from `Derived::children_of_rev` but it was annoying to layer |
| 222 | // it over the output of that function, and perhaps clearer to rewrite in any case. |
| 223 | |
| 224 | // Discard the last element (the size of the expression's subtree). |
| 225 | // Repeatedly read out the last element, then peel off that many elements. |
| 226 | // Each extracted slice corresponds to a child of the current expression. |
| 227 | // We should end cleanly with an empty slice, otherwise there is an issue. |
| 228 | let sizes = self.results::<SubtreeSize>(); |
| 229 | let sizes = &sizes[..sizes.len() - 1]; |
| 230 | |
| 231 | let offset = self.lower; |
| 232 | let derived = self.derived; |
| 233 | (0..).scan(sizes, move |sizes, _| { |
| 234 | if let Some(size) = sizes.last() { |
| 235 | *sizes = &sizes[..sizes.len() - size]; |
| 236 | Some(Self { |
| 237 | derived, |
| 238 | lower: offset + sizes.len(), |
| 239 | upper: offset + sizes.len() + size, |
| 240 | }) |
| 241 | } else { |
| 242 | None |
| 243 | } |
| 244 | }) |
| 245 | } |
| 246 | |
| 247 | /// A convenience method for the view over the expressions last child. |
| 248 | /// |
no test coverage detected