natter/src/context/document_element.rs

36 lines
982 B
Rust
Raw Normal View History

2023-10-27 22:59:40 +00:00
use std::path::Path;
use serde::Serialize;
2023-10-27 22:59:40 +00:00
use crate::config::Config;
use crate::error::CustomError;
use crate::intermediate::IDocumentElement;
use super::RenderHeading;
use super::RenderSection;
#[derive(Debug, Serialize)]
#[serde(untagged)]
pub(crate) enum RenderDocumentElement {
Heading(RenderHeading),
Section(RenderSection),
}
2023-10-27 22:59:40 +00:00
impl RenderDocumentElement {
pub(crate) fn new(
config: &Config,
output_directory: &Path,
output_file: &Path,
original: &IDocumentElement,
) -> Result<RenderDocumentElement, CustomError> {
match original {
IDocumentElement::Heading(inner) => Ok(RenderDocumentElement::Heading(
RenderHeading::new(config, output_directory, output_file, inner)?,
)),
IDocumentElement::Section(inner) => Ok(RenderDocumentElement::Section(
RenderSection::new(config, output_directory, output_file, inner)?,
)),
}
}
}