Skip to main content

Reader

Trait Reader 

Source
pub trait Reader:
    Debug
    + Send
    + Sync {
    // Required methods
    fn name(&self) -> &str;
    fn reads(&self, format: Format) -> bool;
    fn parse(&self, text: &str, format: Format) -> Result<Value, Error>;
}
Expand description

Text in, this crate’s tree out.

Implement it to read a format this crate does not ship, or to read one it does with a parser of your own.

§Errors

A reader’s error must never carry document content. The line that failed to parse is, on a bad day, the line holding the password — so a message says where it stopped and why, and never what it found there.

Required Methods§

Source

fn name(&self) -> &str

What to call this reader in a diagnostic.

Source

fn reads(&self, format: Format) -> bool

Whether this reader can read format in this build.

A reader whose backend was compiled without a format answers false for it, and the load says which reader could have.

Source

fn parse(&self, text: &str, format: Format) -> Result<Value, Error>

text, as this crate’s tree.

The result is always a Value::Table: a document is keys.

§Errors

If the text is not valid in its format.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§