Skip to main content

Render

Trait Render 

Source
pub trait Render {
    // Required method
    fn write_into(
        &self,
        out: &mut String,
        options: &RenderOptions,
        depth: usize,
    );

    // Provided methods
    fn render(&self) -> String { ... }
    fn render_pretty(&self) -> String { ... }
    fn render_with(&self, options: &RenderOptions) -> String { ... }
}
Expand description

Anything that can be written as HTML.

Implement write_into; the rest comes free.

§Depth

The provided implementations walk an explicit work stack rather than recursing, so nesting depth costs heap rather than stack and there is no depth at which rendering aborts. A 100,000-level tree is covered by a test.

Pretty mode still writes one indent string per level on every line, which makes its output quadratic in depth. That is a size to be aware of when depth comes from untrusted input — see SECURITY.md — not a limit on what renders.

Required Methods§

Source

fn write_into(&self, out: &mut String, options: &RenderOptions, depth: usize)

Writes this node and its subtree into an existing buffer.

This is the primitive every other method here is built on. Writing into a shared buffer avoids allocating an intermediate string per node.

Provided Methods§

Source

fn render(&self) -> String

Renders as a single line of markup.

Note the asymmetry with crate::Document::render, which defaults to pretty. That difference is in the Swift original and the golden fixtures depend on it.

Source

fn render_pretty(&self) -> String

Renders with indentation and line breaks.

Source

fn render_with(&self, options: &RenderOptions) -> String

Renders with the given options.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§