Expand description
§Backend Trait
Backend trait for implementing output format backends.
§Overview
The Backend trait defines the interface that backends must implement
to support different output formats (PDF, SVG, TXT, etc.).
§Trait Definition
pub trait Backend: Send + Sync {
fn id(&self) -> &'static str;
fn supported_formats(&self) -> &'static [OutputFormat];
fn glue_extension_types(&self) -> &'static [&'static str];
fn allow_auto_glue(&self) -> bool;
fn register_filters(&self, glue: &mut Glue);
fn compile(
&self,
glue_content: &str,
quill: &Quill,
opts: &RenderOptions,
) -> Result<RenderResult, RenderError>;
}§Implementation Guide
§Required Methods
§id()
Return a unique backend identifier (e.g., “typst”, “latex”).
§supported_formats()
Return a slice of OutputFormat variants this backend supports.
§glue_extension_types()
Return the file extensions for glue files (e.g., &[“.typ”], &[“.tex”]). Return an empty array to disable custom glue files.
§allow_auto_glue()
Return whether automatic JSON glue generation is allowed.
§register_filters()
Register backend-specific filters with the glue environment.
fn register_filters(&self, glue: &mut Glue) {
glue.register_filter("String", string_filter);
glue.register_filter("Content", content_filter);
glue.register_filter("Lines", lines_filter);
}§compile()
Compile glue content into final artifacts.
fn compile(
&self,
glue_content: &str,
quill: &Quill,
opts: &RenderOptions,
) -> Result<RenderResult, RenderError> {
// 1. Create compilation environment
// 2. Load assets from quill
// 3. Compile glue content
// 4. Handle errors and map to Diagnostics
// 5. Return RenderResult with artifacts and output format
let artifacts = vec![Artifact {
bytes: compiled_pdf,
output_format: format,
}];
Ok(RenderResult::new(artifacts, format))
}§Example Implementation
See quillmark-typst for a complete backend implementation example.
§Thread Safety
The Backend trait requires Send + Sync to enable concurrent rendering.
All backend implementations must be thread-safe.
Traits§
- Backend
- Backend trait for rendering different output formats