pub struct Formats { /* private fields */ }json or toml or yaml only.Expand description
The input formats a CLI reads, in the order they were registered.
Self::builtin holds yaml, json and then toml, each with its
feature. A CLI adds a format, replaces a built-in of the same name, or
removes one, then installs the set with set_default_formats. Every
builder takes and returns self, as ctl-core’s output registry does.
use ctl_input::Formats;
let formats = Formats::builtin().remove("json").remove("toml");
assert_eq!(formats.names().collect::<Vec<_>>(), ["yaml"]);Implementations§
Source§impl Formats
impl Formats
Sourcepub fn builtin() -> Self
pub fn builtin() -> Self
yaml with the yaml feature, then json with the json feature,
then toml with the toml feature.
Sourcepub fn add(self, format: &'static dyn Format) -> Self
pub fn add(self, format: &'static dyn Format) -> Self
Register format, or replace the registered format of the same name.
A replacement keeps its place in the list.
Sourcepub fn get(&self, name: &str) -> Option<&'static dyn Format>
pub fn get(&self, name: &str) -> Option<&'static dyn Format>
The registered format called name.
Sourcepub fn names(&self) -> impl Iterator<Item = &'static str> + '_
pub fn names(&self) -> impl Iterator<Item = &'static str> + '_
The registered names, in the order registered.
Sourcepub fn of(&self, path: &Path) -> Result<&'static dyn Format, InputError>
pub fn of(&self, path: &Path) -> Result<&'static dyn Format, InputError>
The registered format that reads a file’s extension, compared without
regard to case: with the built-ins, .toml is TOML, .json is JSON,
and .yaml and .yml are YAML.
§Errors
An InputError with no line for any other extension or none, naming
the extension and the accepted ones. One naming the feature for a
built-in extension whose feature is off.
Sourcepub fn open(&self, path: &Path) -> Result<Input, InputError>
pub fn open(&self, path: &Path) -> Result<Input, InputError>
Read a file with the format this registry has for its extension. The extension is checked before the file is read, so a file no registered format reads is refused without being opened.
Input::open does the same through the registry the process uses.
§Errors
An InputError for an extension Self::of refuses, or with the I/O
failure.