Got rid of the IceTreeIterator by using map().

This commit is contained in:
Tom Alexander 2020-05-31 16:02:30 -04:00
parent 781b8f645a
commit 863744c42d
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE

View File

@ -18,8 +18,8 @@ enum BreadcrumbTreeNodeElement<'a, C: IntoContextElement> {
}
impl<'a, C: IntoContextElement> BreadcrumbTreeNode<'a, C> {
pub fn ice_iter(&'a self) -> IceTreeIterator<'a> {
IceTreeIterator(Some(self))
pub fn ice_iter(&'a self) -> impl Iterator<Item = &dyn IntoContextElement> {
self.breadcrumb_iter().map(|b| b.get_ice())
}
pub fn breadcrumb_iter(&'a self) -> BreadcrumbTreeIterator<'a> {
@ -48,18 +48,6 @@ impl<'a, C: IntoContextElement> BreadcrumbTree for BreadcrumbTreeNode<'a, C> {
}
}
pub struct IceTreeIterator<'a>(Option<&'a dyn BreadcrumbTree>);
impl<'a> Iterator for IceTreeIterator<'a> {
type Item = &'a dyn IntoContextElement;
fn next(&mut self) -> Option<Self::Item> {
let ret = self.0;
self.0 = self.0.map(|node| node.get_parent()).flatten();
ret.map(|node| node.get_ice())
}
}
impl<'a, C: IntoContextElement> IntoIterator for &'a BreadcrumbTreeNode<'a, C> {
type Item = &'a dyn BreadcrumbTree;
type IntoIter = BreadcrumbTreeIterator<'a>;