Switch to using the multi field macro for document and heading.
This commit is contained in:
parent
32a7ce3f36
commit
95fa834420
@ -87,64 +87,22 @@ pub enum AstNodeIter<'r, 's> {
|
||||
// Timestamp(TimestampIter<'r, 's>),
|
||||
}
|
||||
|
||||
pub struct DocumentIter<'r, 's> {
|
||||
zeroth_section_next: std::option::Iter<'r, Section<'s>>,
|
||||
children_next: std::slice::Iter<'r, Heading<'s>>,
|
||||
}
|
||||
|
||||
impl<'r, 's> Iterator for DocumentIter<'r, 's> {
|
||||
type Item = AstNode<'r, 's>;
|
||||
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
self.zeroth_section_next
|
||||
.next()
|
||||
.map(Into::<AstNode>::into)
|
||||
.or_else(|| self.children_next.next().map(Into::<AstNode>::into))
|
||||
}
|
||||
}
|
||||
|
||||
impl<'r, 's> IntoIterator for &'r Document<'s> {
|
||||
type Item = AstNode<'r, 's>;
|
||||
|
||||
type IntoIter = DocumentIter<'r, 's>;
|
||||
|
||||
fn into_iter(self) -> Self::IntoIter {
|
||||
DocumentIter {
|
||||
zeroth_section_next: self.zeroth_section.iter(),
|
||||
children_next: self.children.iter(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct HeadingIter<'r, '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> {
|
||||
type Item = AstNode<'r, 's>;
|
||||
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
self.title_next
|
||||
.next()
|
||||
.map(Into::<AstNode>::into)
|
||||
.or_else(|| self.children_next.next().map(Into::<AstNode>::into))
|
||||
}
|
||||
}
|
||||
|
||||
impl<'r, 's> IntoIterator for &'r Heading<'s> {
|
||||
type Item = AstNode<'r, 's>;
|
||||
|
||||
type IntoIter = HeadingIter<'r, 's>;
|
||||
|
||||
fn into_iter(self) -> Self::IntoIter {
|
||||
HeadingIter {
|
||||
title_next: self.title.iter(),
|
||||
children_next: self.children.iter(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
multi_field_iter!(
|
||||
Document<'s>,
|
||||
DocumentIter,
|
||||
zeroth_section,
|
||||
std::option::Iter<'r, Section<'s>>,
|
||||
children,
|
||||
std::slice::Iter<'r, Heading<'s>>
|
||||
);
|
||||
multi_field_iter!(
|
||||
Heading<'s>,
|
||||
HeadingIter,
|
||||
title,
|
||||
std::slice::Iter<'r, Object<'s>>,
|
||||
children,
|
||||
std::slice::Iter<'r, DocumentElement<'s>>
|
||||
);
|
||||
children_iter!(Section<'s>, SectionIter, std::slice::Iter<'r, Element<'s>>);
|
||||
children_iter!(
|
||||
Paragraph<'s>,
|
||||
@ -156,7 +114,6 @@ children_iter!(
|
||||
PlainListIter,
|
||||
std::slice::Iter<'r, PlainListItem<'s>>
|
||||
);
|
||||
|
||||
multi_field_iter!(
|
||||
PlainListItem<'s>,
|
||||
PlainListItemIter,
|
||||
|
Loading…
Reference in New Issue
Block a user