Switch IntoIter over to the breadcrumb iterator.

This commit is contained in:
Tom Alexander 2020-05-31 15:58:29 -04:00
parent ff13d22ab6
commit 781b8f645a
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
2 changed files with 23 additions and 6 deletions

View File

@ -18,9 +18,13 @@ enum BreadcrumbTreeNodeElement<'a, C: IntoContextElement> {
} }
impl<'a, C: IntoContextElement> BreadcrumbTreeNode<'a, C> { 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)) IceTreeIterator(Some(self))
} }
pub fn breadcrumb_iter(&'a self) -> BreadcrumbTreeIterator<'a> {
BreadcrumbTreeIterator(Some(self))
}
} }
impl<'a, C: IntoContextElement> Borrow<dyn IntoContextElement + 'a> impl<'a, C: IntoContextElement> Borrow<dyn IntoContextElement + 'a>
@ -57,10 +61,22 @@ impl<'a> Iterator for IceTreeIterator<'a> {
} }
impl<'a, C: IntoContextElement> IntoIterator for &'a BreadcrumbTreeNode<'a, C> { impl<'a, C: IntoContextElement> IntoIterator for &'a BreadcrumbTreeNode<'a, C> {
type Item = &'a dyn IntoContextElement; type Item = &'a dyn BreadcrumbTree;
type IntoIter = IceTreeIterator<'a>; type IntoIter = BreadcrumbTreeIterator<'a>;
fn into_iter(self) -> IceTreeIterator<'a> { fn into_iter(self) -> BreadcrumbTreeIterator<'a> {
self.iter() 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<Self::Item> {
let ret = self.0;
self.0 = self.0.map(|node| node.get_parent()).flatten();
ret
} }
} }

View File

@ -24,7 +24,8 @@ fn get_first_non_pseudo_element<'a, B>(
where where
B: IntoContextElement, 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>( pub fn walk_path<'a, B, P>(