2023-10-27 22:59:40 +00:00
|
|
|
use crate::error::CustomError;
|
|
|
|
|
|
|
|
use super::registry::Registry;
|
2023-10-27 17:05:34 +00:00
|
|
|
use super::IHeading;
|
|
|
|
use super::ISection;
|
2023-10-27 22:59:40 +00:00
|
|
|
use futures::future::{BoxFuture, FutureExt};
|
2023-10-27 17:05:34 +00:00
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub(crate) enum IDocumentElement {
|
|
|
|
Heading(IHeading),
|
|
|
|
Section(ISection),
|
|
|
|
}
|
2023-10-27 22:59:40 +00:00
|
|
|
|
|
|
|
impl IDocumentElement {
|
2023-10-29 16:15:07 +00:00
|
|
|
pub(crate) fn new<'intermediate, 'parse, 'b>(
|
|
|
|
registry: &'b mut Registry<'intermediate, 'parse>,
|
|
|
|
original: &'intermediate organic::types::DocumentElement<'parse>,
|
2023-10-27 22:59:40 +00:00
|
|
|
) -> 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()
|
|
|
|
}
|
|
|
|
}
|