Skip to main content

DocumentFormat

Trait DocumentFormat 

Source
pub trait DocumentFormat: Send + Sync {
    // Required methods
    fn id(&self) -> &str;
    fn name(&self) -> &str;

    // Provided methods
    fn aliases(&self) -> Vec<String> { ... }
    fn extensions(&self) -> Vec<String> { ... }
    fn match_name(&self, file_name: &str) -> NameMatch { ... }
    fn sniff(&self, _text: &str) -> f32 { ... }
    fn features(&self) -> Vec<String> { ... }
    fn parse(&self, _source: &str) -> Option<Parsed> { ... }
    fn render(&self, source: &str, options: &RenderOptions) -> Rendered { ... }
}
Expand description

A documentation format: how to recognise it and how to draw it.

Required Methods§

Source

fn id(&self) -> &str

The format’s id: lowercase, stable, usable as a CLI value ("org").

Source

fn name(&self) -> &str

The name people call it ("Org").

Provided Methods§

Source

fn aliases(&self) -> Vec<String>

Other ids accepted for it ("adoc" for AsciiDoc).

Source

fn extensions(&self) -> Vec<String>

The file extensions it claims, lowercase, without the dot.

Source

fn match_name(&self, file_name: &str) -> NameMatch

How file_name (a base name) relates to this format. By default a name whose extension is one of extensions is NameMatch::Yes.

Source

fn sniff(&self, _text: &str) -> f32

How confident it is that text is in this format, from 0 to 1. See LIKELY and CERTAIN.

Source

fn features(&self) -> Vec<String>

What the format supports ("tables", "admonitions", …), for listings and for callers that want to know before rendering.

Source

fn parse(&self, _source: &str) -> Option<Parsed>

Parse source into the shared model, for formats built on it.

Source

fn render(&self, source: &str, options: &RenderOptions) -> Rendered

Render source. The default draws parse’s document with DocumentView, or the source as plain text when the format does not parse into the model.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§