Skip to main content

Format

Enum Format 

Source
pub enum Format {
    Json,
    Toml,
    Yaml,
    Dotenv,
    Ini,
    TomlFrontmatter,
    YamlFrontmatter,
    Markdown,
}
Expand description

A format this build can actually read.

The optional backends gate their variants, not just their bodies: in a build without toml there is no Format::Toml at all, so code naming a format it did not enable fails to compile instead of returning a runtime refusal from deep inside load. Detection still answers for those files — see Format::unavailable — because a file’s format is a fact about the file, not about this build.

Variants§

§

Json

§

Toml

§

Yaml

§

Dotenv

§

Ini

§

TomlFrontmatter

A +++-fenced TOML frontmatter block; the Markdown body is frozen. Never auto-detected — selected only via --input-format toml-frontmatter.

§

YamlFrontmatter

A ----fenced YAML frontmatter block; the Markdown body is frozen. Never auto-detected — selected only via --input-format yaml-frontmatter.

§

Markdown

A CommonMark document read as a tree of heading sections (preamble, h1, h1.0.h2, …). Read-only, and never auto-detected — the same .md file is legitimately readable as frontmatter, and choosing between two valid readings is not something an extension can decide.

Implementations§

Source§

impl Format

Source

pub const fn name(self) -> &'static str

Stable human-readable label used in document results and diagnostics.

Source

pub const fn is_read_only(self) -> bool

Whether this format can be written at all.

Markdown is the one reader-only format: its parsed value is a flattened view of prose, so re-rendering a document from it would discard everything the flattening dropped. Every mutating verb refuses up front rather than producing that file.

Source

pub const fn array_rule(self) -> Option<ArrayRule<'static>>

This format’s own rule for resolving a non-numeric path segment against an array, or None when only a caller-declared keyed list can.

A format earns a rule by owning the shape of its own value. Markdown’s value is a tree afdata synthesized — every node carries text because this crate put it there — so h2.look can be answered from the format alone. JSON, TOML, YAML, dotenv, and INI hand back whatever the file said; nothing in deps.foo tells afdata which field of a deps element foo is supposed to match, and inventing one is the shape-guessing this crate exists to refuse. Those keep needing an explicit KeyedList.

Source

pub const fn cli_name(self) -> &'static str

Exact CLI token accepted by --input-format and emitted in result payloads. Unlike Self::name, this is stable machine data rather than a display label.

Source

pub fn detect(path: &Path) -> Option<Self>

Detect format from file extension, when this build can read it.

Source

pub fn unavailable(path: &Path) -> Option<&'static str>

The Cargo feature a path’s format needs, when this build lacks it.

detect answers None both for a file this crate has never heard of and for one it knows perfectly well but was not built to read. Only the second is worth a different message, and only this can tell them apart, so the caller reports the missing feature instead of calling a .toml file’s format unknown.

Source

pub fn load(&self, content: &str) -> DocumentResult<Value>

Load a config file in the detected format.

Source

pub fn save(&self, value: &Value) -> DocumentResult<String>

Save a config in the target format.

Trait Implementations§

Source§

impl Clone for Format

Source§

fn clone(&self) -> Format

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

Source§

fn eq(&self, other: &Format) -> 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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more