Boxing made it work.

This commit is contained in:
Tom Alexander 2023-07-14 19:57:27 -04:00
parent 0073af19e2
commit 793e560bd5
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE

View File

@ -14,24 +14,22 @@ pub enum Token<'r, 's> {
}
impl<'r, 's> Token<'r, 's> {
pub fn iter_tokens(&self) -> impl Iterator<Item = Token<'r, 's>> {
pub fn iter_tokens(&self) -> Box<dyn Iterator<Item = Token<'r, 's>> + '_> {
match self {
Token::Document(document) => document
.zeroth_section
.iter()
.map(Token::Section)
.chain(document.children.iter().map(Token::Heading)),
Token::Heading(heading) => {
heading
.title
Token::Document(document) => Box::new(
document
.zeroth_section
.iter()
.map(Token::Object)
.chain(heading.children.iter().map(|de| match de {
DocumentElement::Heading(ref obj) => Token::Heading(obj),
DocumentElement::Section(ref obj) => Token::Section(obj),
}))
}
Token::Section(section) => section.children.iter().map(Token::Element),
.map(Token::Section)
.chain(document.children.iter().map(Token::Heading)),
),
Token::Heading(heading) => Box::new(heading.title.iter().map(Token::Object).chain(
heading.children.iter().map(|de| match de {
DocumentElement::Heading(ref obj) => Token::Heading(obj),
DocumentElement::Section(ref obj) => Token::Section(obj),
}),
)),
Token::Section(section) => Box::new(section.children.iter().map(Token::Element)),
Token::Object(_) => panic!(),
Token::Element(_) => panic!(),
}