diff --git a/src/iter/ast_node_iter.rs b/src/iter/ast_node_iter.rs index 0abe9d9..0c55a80 100644 --- a/src/iter/ast_node_iter.rs +++ b/src/iter/ast_node_iter.rs @@ -1,5 +1,6 @@ use super::ast_node::AstNode; use crate::types::Bold; +use crate::types::Italic; use crate::types::Object; pub enum AstNodeIter<'r, 's> { @@ -32,7 +33,7 @@ pub enum AstNodeIter<'r, 's> { // LatexEnvironment(LatexEnvironmentIter<'r, 's>), // Objects Bold(BoldIter<'r, 's>), - // Italic(ItalicIter<'r, 's>), + Italic(ItalicIter<'r, 's>), // Underline(UnderlineIter<'r, 's>), // StrikeThrough(StrikeThroughIter<'r, 's>), // Code(CodeIter<'r, 's>), @@ -83,3 +84,33 @@ impl<'r, 's> IntoIterator for &'r Bold<'s> { } } } + +macro_rules! simple_iter { + ($astnodetype:ty, $itertype:ident, $innertype:ty) => { + pub struct $itertype<'r, 's> { + next: $innertype, + } + + impl<'r, 's> Iterator for $itertype<'r, 's> { + type Item = AstNode<'r, 's>; + + fn next(&mut self) -> Option { + self.next.next().map(Into::::into) + } + } + + impl<'r, 's> IntoIterator for &'r $astnodetype { + type Item = AstNode<'r, 's>; + + type IntoIter = $itertype<'r, 's>; + + fn into_iter(self) -> Self::IntoIter { + $itertype { + next: self.children.iter(), + } + } + } + }; +} + +simple_iter!(Italic<'s>, ItalicIter, std::slice::Iter<'r, Object<'s>>);