Skip to main content

Language

Trait Language 

Source
pub trait Language:
    Send
    + Sync
    + 'static {
    // Required method
    fn describe(&self) -> Description;

    // Provided methods
    fn parse(&self, row: &str, source: &[u8]) -> Result<Vec<u8>, String> { ... }
    fn print(&self, row: &str, table: &[u8]) -> Result<Vec<u8>, String> { ... }
    fn parse_with(
        &self,
        call: &Call<'_>,
        source: &[u8],
    ) -> Result<Vec<u8>, String> { ... }
    fn print_with(
        &self,
        call: &Call<'_>,
        table: &[u8],
    ) -> Result<Vec<u8>, String> { ... }
    fn render(&self, call: &Call<'_>, request: &[u8]) -> Result<Vec<u8>, String> { ... }
}
Expand description

A language supplied at runtime. Called from whichever thread parses or prints, hence Send + Sync; kept for the life of the process, since there is no unregistration.

A language implements Language::parse, or Language::parse_with when it reads features; the same for printing.

Required Methods§

Provided Methods§

Source

fn parse(&self, row: &str, source: &[u8]) -> Result<Vec<u8>, String>

source to the node table of its parse, as JSON. row is the name the call is through. An Err is a parse error whose message the library reports.

Source

fn print(&self, row: &str, table: &[u8]) -> Result<Vec<u8>, String>

A node table without positions to source. Called only for a language whose description declares write.

Source

fn parse_with(&self, call: &Call<'_>, source: &[u8]) -> Result<Vec<u8>, String>

Language::parse, told the features in force.

Source

fn print_with(&self, call: &Call<'_>, table: &[u8]) -> Result<Vec<u8>, String>

Language::print, told the features in force.

Source

fn render(&self, call: &Call<'_>, request: &[u8]) -> Result<Vec<u8>, String>

Answer one of the renderers the description’s syntax names. The request is JSON, as the node tables are:

  • {"which":"render_text","text":…,"position":…} — spell text so it reparses as itself, at position inline_text, block_start or verbatim;
  • {"which":"render_block","table":{…}} — spell a fragment: a node table without positions, rooted at the node to print;
  • {"which":"spells_autolink","text":"<…>"} — answer true or false.

The default answers render_block with Language::print_with — so a language whose print spells every fragment a gesture builds names render_block and writes nothing more — and refuses the rest. One whose table states text_escapes names no render_text.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§