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§
fn describe(&self) -> Description
Provided Methods§
Sourcefn parse(&self, row: &str, source: &[u8]) -> Result<Vec<u8>, String>
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.
Sourcefn print(&self, row: &str, table: &[u8]) -> Result<Vec<u8>, String>
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.
Sourcefn parse_with(&self, call: &Call<'_>, source: &[u8]) -> Result<Vec<u8>, String>
fn parse_with(&self, call: &Call<'_>, source: &[u8]) -> Result<Vec<u8>, String>
Language::parse, told the features in force.
Sourcefn print_with(&self, call: &Call<'_>, table: &[u8]) -> Result<Vec<u8>, String>
fn print_with(&self, call: &Call<'_>, table: &[u8]) -> Result<Vec<u8>, String>
Language::print, told the features in force.
Sourcefn render(&self, call: &Call<'_>, request: &[u8]) -> Result<Vec<u8>, String>
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":…}— spelltextso it reparses as itself, atpositioninline_text,block_startorverbatim;{"which":"render_block","table":{…}}— spell a fragment: a node table without positions, rooted at the node to print;{"which":"spells_autolink","text":"<…>"}— answertrueorfalse.
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".