Skip to main content

Formats

Struct Formats 

Source
pub struct Formats { /* private fields */ }
Available on crate features 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

Source

pub fn builtin() -> Self

yaml with the yaml feature, then json with the json feature, then toml with the toml feature.

Source

pub const fn empty() -> Self

No format: Self::of refuses every extension.

Source

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.

Source

pub fn remove(self, name: &str) -> Self

Take the format called name out.

Source

pub fn get(&self, name: &str) -> Option<&'static dyn Format>

The registered format called name.

Source

pub fn names(&self) -> impl Iterator<Item = &'static str> + '_

The registered names, in the order registered.

Source

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.

Source

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.

Trait Implementations§

Source§

impl Clone for Formats

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Formats

Names the registered formats: a format has no Debug.

Source§

fn fmt(&self, formatter: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.