use crate::error::CustomError; use super::comment::IComment; use super::keyword::IKeyword; use super::registry::Registry; use super::IBabelCall; use super::ICenterBlock; use super::IClock; use super::ICommentBlock; use super::IDiarySexp; use super::IDrawer; use super::IDynamicBlock; use super::IExampleBlock; use super::IExportBlock; use super::IFixedWidthArea; use super::IFootnoteDefinition; use super::IHorizontalRule; use super::ILatexEnvironment; use super::IParagraph; use super::IPlainList; use super::IPlanning; use super::IPropertyDrawer; use super::IQuoteBlock; use super::ISpecialBlock; use super::ISrcBlock; use super::ITable; use super::IVerseBlock; use futures::future::{BoxFuture, FutureExt}; #[derive(Debug)] pub(crate) enum IElement { Paragraph(IParagraph), PlainList(IPlainList), CenterBlock(ICenterBlock), QuoteBlock(IQuoteBlock), SpecialBlock(ISpecialBlock), DynamicBlock(IDynamicBlock), FootnoteDefinition(IFootnoteDefinition), Comment(IComment), Drawer(IDrawer), PropertyDrawer(IPropertyDrawer), Table(ITable), VerseBlock(IVerseBlock), CommentBlock(ICommentBlock), ExampleBlock(IExampleBlock), ExportBlock(IExportBlock), SrcBlock(ISrcBlock), Clock(IClock), DiarySexp(IDiarySexp), Planning(IPlanning), FixedWidthArea(IFixedWidthArea), HorizontalRule(IHorizontalRule), Keyword(IKeyword), BabelCall(IBabelCall), LatexEnvironment(ILatexEnvironment), } impl IElement { pub(crate) fn new<'parse, 'b>( registry: &'b mut Registry<'parse>, elem: &'b organic::types::Element<'parse>, ) -> BoxFuture<'b, Result> { async move { match elem { organic::types::Element::Paragraph(inner) => { Ok(IElement::Paragraph(IParagraph::new(registry, inner).await?)) } organic::types::Element::PlainList(inner) => { Ok(IElement::PlainList(IPlainList::new(registry, inner).await?)) } organic::types::Element::CenterBlock(inner) => Ok(IElement::CenterBlock( ICenterBlock::new(registry, inner).await?, )), organic::types::Element::QuoteBlock(inner) => Ok(IElement::QuoteBlock( IQuoteBlock::new(registry, inner).await?, )), organic::types::Element::SpecialBlock(inner) => Ok(IElement::SpecialBlock( ISpecialBlock::new(registry, inner).await?, )), organic::types::Element::DynamicBlock(inner) => Ok(IElement::DynamicBlock( IDynamicBlock::new(registry, inner).await?, )), organic::types::Element::FootnoteDefinition(inner) => Ok( IElement::FootnoteDefinition(IFootnoteDefinition::new(registry, inner).await?), ), organic::types::Element::Comment(inner) => { Ok(IElement::Comment(IComment::new(registry, inner).await?)) } organic::types::Element::Drawer(inner) => { Ok(IElement::Drawer(IDrawer::new(registry, inner).await?)) } organic::types::Element::PropertyDrawer(inner) => Ok(IElement::PropertyDrawer( IPropertyDrawer::new(registry, inner).await?, )), organic::types::Element::Table(inner) => { Ok(IElement::Table(ITable::new(registry, inner).await?)) } organic::types::Element::VerseBlock(inner) => Ok(IElement::VerseBlock( IVerseBlock::new(registry, inner).await?, )), organic::types::Element::CommentBlock(inner) => Ok(IElement::CommentBlock( ICommentBlock::new(registry, inner).await?, )), organic::types::Element::ExampleBlock(inner) => Ok(IElement::ExampleBlock( IExampleBlock::new(registry, inner).await?, )), organic::types::Element::ExportBlock(inner) => Ok(IElement::ExportBlock( IExportBlock::new(registry, inner).await?, )), organic::types::Element::SrcBlock(inner) => { Ok(IElement::SrcBlock(ISrcBlock::new(registry, inner).await?)) } organic::types::Element::Clock(inner) => { Ok(IElement::Clock(IClock::new(registry, inner).await?)) } organic::types::Element::DiarySexp(inner) => { Ok(IElement::DiarySexp(IDiarySexp::new(registry, inner).await?)) } organic::types::Element::Planning(inner) => { Ok(IElement::Planning(IPlanning::new(registry, inner).await?)) } organic::types::Element::FixedWidthArea(inner) => Ok(IElement::FixedWidthArea( IFixedWidthArea::new(registry, inner).await?, )), organic::types::Element::HorizontalRule(inner) => Ok(IElement::HorizontalRule( IHorizontalRule::new(registry, inner).await?, )), organic::types::Element::Keyword(inner) => { Ok(IElement::Keyword(IKeyword::new(registry, inner).await?)) } organic::types::Element::BabelCall(inner) => { Ok(IElement::BabelCall(IBabelCall::new(registry, inner).await?)) } organic::types::Element::LatexEnvironment(inner) => Ok(IElement::LatexEnvironment( ILatexEnvironment::new(registry, inner).await?, )), } } .boxed() } }