natter/src/intermediate/document_element.rs
2023-10-29 12:24:49 -04:00

32 lines
974 B
Rust

use crate::error::CustomError;
use super::registry::Registry;
use super::IHeading;
use super::ISection;
use futures::future::{BoxFuture, FutureExt};
#[derive(Debug)]
pub(crate) enum IDocumentElement {
Heading(IHeading),
Section(ISection),
}
impl IDocumentElement {
pub(crate) fn new<'intermediate, 'parse, 'b>(
registry: &'b mut Registry<'intermediate, 'parse>,
original: &'intermediate organic::types::DocumentElement<'parse>,
) -> BoxFuture<'b, Result<IDocumentElement, CustomError>> {
async move {
match original {
organic::types::DocumentElement::Heading(inner) => Ok(IDocumentElement::Heading(
IHeading::new(registry, inner).await?,
)),
organic::types::DocumentElement::Section(inner) => Ok(IDocumentElement::Section(
ISection::new(registry, inner).await?,
)),
}
}
.boxed()
}
}