pub trait Format: Sync {
// Required methods
fn name(&self) -> &'static str;
fn extensions(&self) -> &'static [&'static str];
fn read(
&self,
text: &str,
limits: &Limits,
reading: Reading,
) -> Result<Node, Refusal>;
fn resolve<'a>(
&self,
scalar: &'a Scalar,
tag: Option<&Tag>,
wanted: Wanted,
) -> Result<Resolved<'a>, Mismatch>;
}json or toml or yaml only.Expand description
A way to write input, read into the located tree.
The trait is object safe: Formats holds
&'static dyn Format, as ctl-core’s output registry does.
use ctl_input::Limits;
use ctl_input::format::{Format, Reading, YAML};
let formats: Vec<&'static dyn Format> = vec![&YAML];
let tree = formats[0].read("a: 1\n", &Limits::NONE, Reading::Strict)?;
assert_eq!(tree.span(), 0..4);Required Methods§
Sourcefn extensions(&self) -> &'static [&'static str]
fn extensions(&self) -> &'static [&'static str]
The file extensions the format reads, in lower case and without the
dot, such as yaml and yml.
Sourcefn read(
&self,
text: &str,
limits: &Limits,
reading: Reading,
) -> Result<Node, Refusal>
fn read( &self, text: &str, limits: &Limits, reading: Reading, ) -> Result<Node, Refusal>
Read text into the tree, under limits.
The read refuses a second document and anything past a limit, and
reading says whether it also refuses duplicate and merge keys. A
format with aliases expands each one while it reads, so the tree holds
no alias node.
§Errors
A Refusal naming the fault and where it is.
Sourcefn resolve<'a>(
&self,
scalar: &'a Scalar,
tag: Option<&Tag>,
wanted: Wanted,
) -> Result<Resolved<'a>, Mismatch>
fn resolve<'a>( &self, scalar: &'a Scalar, tag: Option<&Tag>, wanted: Wanted, ) -> Result<Resolved<'a>, Mismatch>
Read one scalar, with the tag its node carries, as the type a
field wanted.
This applies the rules of a Reading::Strict read, whichever
reading built the tree: YAML, for one, refuses .inf and .nan for
Wanted::Any. A listing asks of each value only whether it is text,
with Wanted::Str.
§Errors
A Mismatch when the scalar cannot be read as wanted.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".