pub struct Format(/* private fields */);Expand description
A config format: an opaque, per-process handle naming a dialect registered with fig’s core.
A Format is obtained by name — Format::by_name("yaml") — or from
language::register and Format::detect; it cannot be built from an
integer. Handles are assigned in registration
order and differ between processes: persist Format::name and resolve it
again with Format::by_name, never the handle.
The core carries no language: each is a crate of its own
(fig-yaml, …) whose register() returns its first dialect’s format, and
until a language is registered Format::by_name returns None for its
names. Besides the dialect names, a language’s --spec versions are
dialects of their own (yaml-1.1, yaml-1.2.2, toml-1.0, …).
Implementations§
Source§impl Format
impl Format
Sourcepub fn by_name(name: &str) -> Option<Format>
pub fn by_name(name: &str) -> Option<Format>
The registered format named name ("json5", "yaml", "yaml-1.1",
or a language registered at runtime). None when nothing answers to it
in this process — a misspelling, or a language this build compiled out.
Sourcepub fn name(self) -> &'static str
pub fn name(self) -> &'static str
The dialect name this format was registered under — the name
Format::by_name resolves back to this handle.
Every Format this crate hands out names a registered dialect, and
the core never forgets one, so the name is always there; should the
core ever answer with none (or with a name that is not UTF-8), this is
the empty string, which Format::by_name resolves to nothing.
Sourcepub fn split_stream(self, input: &[u8]) -> Result<Vec<StreamDocument>, Error>
pub fn split_stream(self, input: &[u8]) -> Result<Vec<StreamDocument>, Error>
The documents of a multi-document stream in this format (YAML’s
---/...), each a byte range of input to parse as a document of
its own. An empty stream is one document.
Error::UnsupportedOperation for a format without streams.