Implementing HeadingIter but I do not think it can be generic enough for a macro.
Hopefully most types won't need so much care.
This commit is contained in:
parent
ab46a9e5c6
commit
282417ee94
@ -5,6 +5,8 @@ use super::macros::children_iter;
|
|||||||
use super::macros::empty_iter;
|
use super::macros::empty_iter;
|
||||||
use crate::types::Bold;
|
use crate::types::Bold;
|
||||||
use crate::types::Code;
|
use crate::types::Code;
|
||||||
|
use crate::types::DocumentElement;
|
||||||
|
use crate::types::Element;
|
||||||
use crate::types::Heading;
|
use crate::types::Heading;
|
||||||
use crate::types::Italic;
|
use crate::types::Italic;
|
||||||
use crate::types::Object;
|
use crate::types::Object;
|
||||||
@ -79,14 +81,18 @@ pub enum AstNodeIter<'r, 's> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub struct HeadingIter<'r, 's> {
|
pub struct HeadingIter<'r, 's> {
|
||||||
next: std::slice::Iter<'r, Object<'s>>,
|
title_next: std::slice::Iter<'r, Object<'s>>,
|
||||||
|
children_next: std::slice::Iter<'r, DocumentElement<'s>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'r, 's> Iterator for HeadingIter<'r, 's> {
|
impl<'r, 's> Iterator for HeadingIter<'r, 's> {
|
||||||
type Item = AstNode<'r, 's>;
|
type Item = AstNode<'r, 's>;
|
||||||
|
|
||||||
fn next(&mut self) -> Option<Self::Item> {
|
fn next(&mut self) -> Option<Self::Item> {
|
||||||
self.next.next().map(Into::<AstNode>::into)
|
self.title_next
|
||||||
|
.next()
|
||||||
|
.map(Into::<AstNode>::into)
|
||||||
|
.or_else(|| self.children_next.next().map(Into::<AstNode>::into))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -97,11 +103,8 @@ impl<'r, 's> IntoIterator for &'r Heading<'s> {
|
|||||||
|
|
||||||
fn into_iter(self) -> Self::IntoIter {
|
fn into_iter(self) -> Self::IntoIter {
|
||||||
HeadingIter {
|
HeadingIter {
|
||||||
next: self
|
title_next: self.title.iter(),
|
||||||
.title
|
children_next: self.children.iter(),
|
||||||
.iter()
|
|
||||||
.map(Into::<AstNode>::into)
|
|
||||||
.chain(self.children.iter().map(Into::<AstNode>::into)),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user