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> { 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 { match self {
Token::Document(document) => document Token::Document(document) => Box::new(
document
.zeroth_section .zeroth_section
.iter() .iter()
.map(Token::Section) .map(Token::Section)
.chain(document.children.iter().map(Token::Heading)), .chain(document.children.iter().map(Token::Heading)),
Token::Heading(heading) => { ),
heading Token::Heading(heading) => Box::new(heading.title.iter().map(Token::Object).chain(
.title heading.children.iter().map(|de| match de {
.iter()
.map(Token::Object)
.chain(heading.children.iter().map(|de| match de {
DocumentElement::Heading(ref obj) => Token::Heading(obj), DocumentElement::Heading(ref obj) => Token::Heading(obj),
DocumentElement::Section(ref obj) => Token::Section(obj), DocumentElement::Section(ref obj) => Token::Section(obj),
})) }),
} )),
Token::Section(section) => section.children.iter().map(Token::Element), Token::Section(section) => Box::new(section.children.iter().map(Token::Element)),
Token::Object(_) => panic!(), Token::Object(_) => panic!(),
Token::Element(_) => panic!(), Token::Element(_) => panic!(),
} }