rst_renderer/
lib.rs

1#![warn(clippy::pedantic)]
2
3mod html;
4
5use std::io::Write;
6
7use anyhow::{Error, anyhow};
8
9use document_tree::Document;
10
11/// Render a document tree as JSON.
12///
13/// # Errors
14/// Returns an error if serialization fails.
15pub fn render_json<W>(document: &Document, stream: W) -> Result<(), Error>
16where
17    W: Write,
18{
19    serde_json::to_writer(stream, &document)?;
20    Ok(())
21}
22
23/// Render a document tree as XML.
24///
25/// # Errors
26/// Returns an error if serialization fails.
27pub fn render_xml<W>(document: &Document, stream: W) -> Result<(), Error>
28where
29    W: Write,
30{
31    serde_xml_rs::to_writer(stream, &document)
32        .map_err(|e| anyhow!("Failed to serialize XML: {}", e))?;
33    Ok(())
34}
35
36pub use html::render_html;