Skip to main content

Engine

Struct Engine 

Source
pub struct Engine { /* private fields */ }

Implementations§

Source§

impl Engine

Source

pub fn new() -> Self

Source

pub fn with_fixed_today(self, today: Option<NaiveDate>) -> Self

Overrides the “today” value used by diagrams that depend on local time (e.g. Gantt).

This exists primarily to make fixture snapshots deterministic. By default, Mermaid uses the current local date.

Source

pub fn with_fixed_local_offset_minutes( self, offset_minutes: Option<i32>, ) -> Self

Overrides the local timezone offset (in minutes) used by diagrams that depend on local time semantics (notably Gantt).

This exists primarily to make fixture snapshots deterministic across CI runners. When None, the system local timezone is used.

Source

pub fn with_site_config(self, site_config: MermaidConfig) -> Self

Source

pub fn registry(&self) -> &DetectorRegistry

Source

pub fn registry_mut(&mut self) -> &mut DetectorRegistry

Source

pub fn diagram_registry(&self) -> &DiagramRegistry

Source

pub fn diagram_registry_mut(&mut self) -> &mut DiagramRegistry

Source

pub fn parse_metadata_sync( &self, text: &str, options: ParseOptions, ) -> Result<Option<ParseMetadata>>

Synchronous variant of Engine::parse_metadata.

This is useful for UI render pipelines that are synchronous (e.g. immediate-mode UI), where introducing an async executor would be awkward. The parsing work is CPU-bound and does not perform I/O.

Source

pub fn parse_metadata_as_sync( &self, diagram_type: &str, text: &str, options: ParseOptions, ) -> Result<Option<ParseMetadata>>

Parses metadata for an already-known diagram type (skips type detection).

This is intended for integrations that already know the diagram type, e.g. Markdown fences like ````mermaid/ flowchart` / ` sequenceDiagram`.

§Example (Markdown fence)
use merman_core::{Engine, ParseOptions};

let engine = Engine::new();

// Your markdown parser provides the fence info string (e.g. "flowchart", "sequenceDiagram").
let fence = "sequenceDiagram";
let diagram = r#"sequenceDiagram
  Alice->>Bob: Hello
"#;

// Map fence info strings to merman's internal diagram ids.
let diagram_type = match fence {
    "sequenceDiagram" => "sequence",
    "flowchart" | "graph" => "flowchart-v2",
    "stateDiagram" | "stateDiagram-v2" => "stateDiagram",
    other => other,
};

let meta = engine
    .parse_metadata_as_sync(diagram_type, diagram, ParseOptions::strict())?
    .expect("diagram detected");
Source

pub async fn parse_metadata( &self, text: &str, options: ParseOptions, ) -> Result<Option<ParseMetadata>>

Source

pub async fn parse_metadata_as( &self, diagram_type: &str, text: &str, options: ParseOptions, ) -> Result<Option<ParseMetadata>>

Source

pub fn parse_diagram_sync( &self, text: &str, options: ParseOptions, ) -> Result<Option<ParsedDiagram>>

Synchronous variant of Engine::parse_diagram.

Note: callers that want “always returns a diagram” behavior can set ParseOptions::suppress_errors to true to get an error diagram on parse failures.

Source

pub async fn parse_diagram( &self, text: &str, options: ParseOptions, ) -> Result<Option<ParsedDiagram>>

Source

pub fn parse_diagram_for_render_sync( &self, text: &str, options: ParseOptions, ) -> Result<Option<ParsedDiagram>>

Parses a diagram for layout/render pipelines.

Compared to Engine::parse_diagram_sync, this may omit semantic-model keys that are not required by merman’s layout/SVG renderers (e.g. embedding the full effective config into the returned model). This keeps the public parse_diagram* APIs stable while allowing render pipelines to avoid paying large JSON clone costs.

Source

pub async fn parse_diagram_for_render( &self, text: &str, options: ParseOptions, ) -> Result<Option<ParsedDiagram>>

Source

pub fn parse_diagram_for_render_model_sync( &self, text: &str, options: ParseOptions, ) -> Result<Option<ParsedDiagramRender>>

Parses a diagram into a typed semantic model optimized for headless layout + SVG rendering.

Unlike Engine::parse_diagram_for_render_sync, this avoids constructing large serde_json::Value object trees for some high-impact diagrams (currently stateDiagram and mindmap) and instead returns typed semantic structs that the renderer can consume directly.

Callers that need the semantic JSON model should continue using Engine::parse_diagram_sync or Engine::parse_diagram_for_render_sync.

Source

pub async fn parse_diagram_for_render_model( &self, text: &str, options: ParseOptions, ) -> Result<Option<ParsedDiagramRender>>

Source

pub fn parse_diagram_for_render_model_as_sync( &self, diagram_type: &str, text: &str, options: ParseOptions, ) -> Result<Option<ParsedDiagramRender>>

Parses a diagram into a typed semantic render model when the diagram type is already known (skips type detection).

This is the preferred entrypoint for Markdown renderers and editors that already know the diagram type from the code fence info string. It avoids the detection pass and can reduce a small fixed overhead in tight render loops.

Source

pub async fn parse_diagram_for_render_model_as( &self, diagram_type: &str, text: &str, options: ParseOptions, ) -> Result<Option<ParsedDiagramRender>>

Source

pub fn parse_diagram_as_sync( &self, diagram_type: &str, text: &str, options: ParseOptions, ) -> Result<Option<ParsedDiagram>>

Parses a diagram when the diagram type is already known (skips type detection).

This is the preferred entrypoint for Markdown renderers and editors that already know the diagram type from the code fence info string. It avoids the detection pass and can reduce a small fixed overhead in tight render loops.

§Example
use merman_core::{Engine, ParseOptions};

let engine = Engine::new();
let input = "flowchart TD; A-->B;";

let parsed = engine
    .parse_diagram_as_sync("flowchart-v2", input, ParseOptions::strict())?
    .expect("diagram detected");

assert_eq!(parsed.meta.diagram_type, "flowchart-v2");
Source

pub async fn parse_diagram_as( &self, diagram_type: &str, text: &str, options: ParseOptions, ) -> Result<Option<ParsedDiagram>>

Source

pub async fn parse( &self, text: &str, options: ParseOptions, ) -> Result<Option<ParseMetadata>>

Trait Implementations§

Source§

impl Clone for Engine

Source§

fn clone(&self) -> Engine

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Engine

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Engine

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.