From 781b8f645a1681040c39ac676586c07d727b7c50 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Sun, 31 May 2020 15:58:29 -0400 Subject: [PATCH] Switch IntoIter over to the breadcrumb iterator. --- src/renderer/breadcrumb_tree.rs | 26 +++++++++++++++++++++----- src/renderer/tree_walking.rs | 3 ++- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/src/renderer/breadcrumb_tree.rs b/src/renderer/breadcrumb_tree.rs index 00e1804..b4bc32a 100644 --- a/src/renderer/breadcrumb_tree.rs +++ b/src/renderer/breadcrumb_tree.rs @@ -18,9 +18,13 @@ enum BreadcrumbTreeNodeElement<'a, C: IntoContextElement> { } impl<'a, C: IntoContextElement> BreadcrumbTreeNode<'a, C> { - pub fn iter(&'a self) -> IceTreeIterator<'a> { + pub fn ice_iter(&'a self) -> IceTreeIterator<'a> { IceTreeIterator(Some(self)) } + + pub fn breadcrumb_iter(&'a self) -> BreadcrumbTreeIterator<'a> { + BreadcrumbTreeIterator(Some(self)) + } } impl<'a, C: IntoContextElement> Borrow @@ -57,10 +61,22 @@ impl<'a> Iterator for IceTreeIterator<'a> { } impl<'a, C: IntoContextElement> IntoIterator for &'a BreadcrumbTreeNode<'a, C> { - type Item = &'a dyn IntoContextElement; - type IntoIter = IceTreeIterator<'a>; + type Item = &'a dyn BreadcrumbTree; + type IntoIter = BreadcrumbTreeIterator<'a>; - fn into_iter(self) -> IceTreeIterator<'a> { - self.iter() + fn into_iter(self) -> BreadcrumbTreeIterator<'a> { + self.breadcrumb_iter() + } +} + +pub struct BreadcrumbTreeIterator<'a>(Option<&'a dyn BreadcrumbTree>); + +impl<'a> Iterator for BreadcrumbTreeIterator<'a> { + type Item = &'a dyn BreadcrumbTree; + + fn next(&mut self) -> Option { + let ret = self.0; + self.0 = self.0.map(|node| node.get_parent()).flatten(); + ret } } diff --git a/src/renderer/tree_walking.rs b/src/renderer/tree_walking.rs index 574c99e..65f6cbd 100644 --- a/src/renderer/tree_walking.rs +++ b/src/renderer/tree_walking.rs @@ -24,7 +24,8 @@ fn get_first_non_pseudo_element<'a, B>( where B: IntoContextElement, { - breadcrumbs.iter().filter(|b| b.is_pseudo_element()).next() + todo!() + // breadcrumbs.iter().filter(|b| b.is_pseudo_element()).next() } pub fn walk_path<'a, B, P>(