Rust API
Rust API
Section titled “Rust API”The plantuml-engine crate provides the unified render API — the same entry point used by all language bindings.
render_svg
Section titled “render_svg”Renders PlantUML source to an SVG string. Returns RenderError::ParseFailed when the source cannot be parsed as a supported diagram type (currently sequence diagrams only).
use plantuml_engine::render_svg;
let svg = render_svg("@startuml\nAlice -> Bob: hello\n@enduml")?;Signature:
pub fn render_svg(source: &str) -> Result<String, RenderError>render_preproc
Section titled “render_preproc”Renders PlantUML source to PREPROC (preprocessed) text — the output of the TIM engine after applying !include, !define, variables, and conditionals.
use plantuml_engine::render_preproc;
let text = render_preproc("@startuml\n!define FOO bar\nAlice -> Bob: FOO\n@enduml")?;Signature:
pub fn render_preproc(source: &str) -> Result<String, RenderError>render
Section titled “render”Dispatches to the appropriate renderer based on the requested FileFormat. Currently supports FileFormat::Svg and FileFormat::Preproc; all other formats return RenderError::UnsupportedFormat.
use plantuml_engine::render;use plantuml_core::FileFormat;
let svg = render("@startuml\nAlice -> Bob: hello\n@enduml", FileFormat::Svg)?;Signature:
pub fn render(source: &str, format: FileFormat) -> Result<String, RenderError>Error handling
Section titled “Error handling”RenderError is the error type returned by all three functions:
pub enum RenderError { ParseFailed, UnsupportedFormat(FileFormat), Utf8(std::string::FromUtf8Error),}ParseFailed— the source could not be parsed as a supported diagram type.UnsupportedFormat(FileFormat)— the requested format is not yet implemented.Utf8— the rendered output was not valid UTF-8.
Add to your project
Section titled “Add to your project”cargo add plantuml-engine plantuml-core