Skip to main content

Format

Struct Format 

Source
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

Source

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.

Source

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.

Source

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.

Source

pub fn detect(input: &[u8], order: &[&str]) -> Option<Format>

The first format order names whose parser accepts input, tried in that order: content sniffing, with the order the caller’s to choose. The grammars overlap, so put the strictest first. A name nothing answers to is skipped.

Trait Implementations§

Source§

impl Clone for Format

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 Copy for Format

Source§

impl Debug for Format

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Eq for Format

Source§

impl Hash for Format

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Format

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Format

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.