Skip to main content

switchback_traits/traits/
renderer.rs

1//! Renderer seam (async primary + sync secondary).
2
3use crate::{ReferenceManual, Result};
4
5/// One rendered output file (path relative to book root unless absolute).
6#[derive(Clone, Debug, PartialEq, Eq)]
7pub struct OutputFile {
8    /// Output path relative to the mdBook root (or absolute when required).
9    pub path: String,
10    /// Rendered file content bytes (typically UTF-8 markdown).
11    pub content: Vec<u8>,
12}
13
14/// Async renderer for service-side and streaming pipelines.
15///
16/// Primary API per [ADR 0002](https://github.com/canardleteer/switchback-rs/blob/main/docs/adr/0002-async-first-traits-with-synchronous-secondary-apis-in-switchback-traits.md).
17/// Renderer crates implement this trait against a family-specific [`Options`](crate::Options) type.
18pub trait Renderer: Send + Sync {
19    /// Renderer-specific options (layout, paths, escaping, etc.).
20    type Opts: Send + Sync;
21
22    /// Renders a [`ReferenceManual`] into one or more output files.
23    async fn render(&self, manual: &ReferenceManual, opts: &Self::Opts) -> Result<Vec<OutputFile>>;
24}
25
26/// Synchronous compatibility API for callers that cannot wrap [`Renderer`].
27///
28/// Secondary API per ADR 0002. Prefer [`Renderer`] for async pipelines.
29pub trait SyncRenderer: Send + Sync {
30    /// Renderer-specific options (layout, paths, escaping, etc.).
31    type Opts: Send + Sync;
32
33    /// Renders a [`ReferenceManual`] into one or more output files.
34    fn render(&self, manual: &ReferenceManual, opts: &Self::Opts) -> Result<Vec<OutputFile>>;
35}