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>),
|
// Timestamp(TimestampIter<'r, 's>),
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct DocumentIter<'r, 's> {
|
multi_field_iter!(
|
||||||
zeroth_section_next: std::option::Iter<'r, Section<'s>>,
|
Document<'s>,
|
||||||
children_next: std::slice::Iter<'r, Heading<'s>>,
|
DocumentIter,
|
||||||
}
|
zeroth_section,
|
||||||
|
std::option::Iter<'r, Section<'s>>,
|
||||||
impl<'r, 's> Iterator for DocumentIter<'r, 's> {
|
children,
|
||||||
type Item = AstNode<'r, 's>;
|
std::slice::Iter<'r, Heading<'s>>
|
||||||
|
);
|
||||||
fn next(&mut self) -> Option<Self::Item> {
|
multi_field_iter!(
|
||||||
self.zeroth_section_next
|
Heading<'s>,
|
||||||
.next()
|
HeadingIter,
|
||||||
.map(Into::<AstNode>::into)
|
title,
|
||||||
.or_else(|| self.children_next.next().map(Into::<AstNode>::into))
|
std::slice::Iter<'r, Object<'s>>,
|
||||||
}
|
children,
|
||||||
}
|
std::slice::Iter<'r, DocumentElement<'s>>
|
||||||
|
);
|
||||||
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(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
children_iter!(Section<'s>, SectionIter, std::slice::Iter<'r, Element<'s>>);
|
children_iter!(Section<'s>, SectionIter, std::slice::Iter<'r, Element<'s>>);
|
||||||
children_iter!(
|
children_iter!(
|
||||||
Paragraph<'s>,
|
Paragraph<'s>,
|
||||||
@ -156,7 +114,6 @@ children_iter!(
|
|||||||
PlainListIter,
|
PlainListIter,
|
||||||
std::slice::Iter<'r, PlainListItem<'s>>
|
std::slice::Iter<'r, PlainListItem<'s>>
|
||||||
);
|
);
|
||||||
|
|
||||||
multi_field_iter!(
|
multi_field_iter!(
|
||||||
PlainListItem<'s>,
|
PlainListItem<'s>,
|
||||||
PlainListItemIter,
|
PlainListItemIter,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user