[][src]Trait figment::providers::Format

pub trait Format: Sized {
    type Error: Error;

    pub const NAME: &'static str;

    pub fn from_str<'de, T: DeserializeOwned>(
        string: &'de str
    ) -> Result<T, Self::Error>; pub fn from_path<T: DeserializeOwned>(path: &Path) -> Result<T, Self::Error> { ... }
pub fn file<P: AsRef<Path>>(path: P) -> Data<Self> { ... }
pub fn string(string: &str) -> Data<Self> { ... } }

Trait implementable by text-based Data format providers.

Instead of implementing Provider directly, types that refer to data formats, such as Json and Toml, implement this trait. By implementing Format, they become Providers indirectly via the Data type, which serves as a provider for all T: Format.

Implementing

There are two primary implementation items to consider:

  1. NAME: This should be the name of the data format: "JSON" or "TOML". The string is used in the metadata for Data.

  2. from_str(): This is the core string deserialization method, for instance, toml::from_str. For writing a custom data format, see serde's writing a data format guide.

Associated Types

type Error: Error[src]

The data format's error type.

Loading content...

Associated Constants

pub const NAME: &'static str[src]

The name of the data format, for instance "JSON" or "TOML".

Loading content...

Required methods

pub fn from_str<'de, T: DeserializeOwned>(
    string: &'de str
) -> Result<T, Self::Error>
[src]

Parses string as the data format Self as a T or returns an error if the string is an invalid T.

Loading content...

Provided methods

pub fn from_path<T: DeserializeOwned>(path: &Path) -> Result<T, Self::Error>[src]

Parses the file at path as the data format Self as a T or returns an error if the string is an invalid T. The default implementation calls Format::from_str() with the contents of the file.

pub fn file<P: AsRef<Path>>(path: P) -> Data<Self>[src]

Returns a Data provider that sources its values by parsing the file at path as format Self. See Data::file() for more details. The default implementation calls Data::file(path).

pub fn string(string: &str) -> Data<Self>[src]

Returns a Data provider that sources its values by parsing string as format Self. See Data::string() for more details. The default implementation calls Data::string(string).

Loading content...

Implementors

impl Format for Json[src]

type Error = Error

impl Format for Toml[src]

type Error = Error

impl Format for Yaml[src]

type Error = Error

Loading content...