#[non_exhaustive]
pub enum Source {
    File(PathBuf),
    Code(&'static Location<'static>),
    Custom(String),
}
Expand description

The source for a configuration value.

The Source of a given value can be determined via that value’s Metadata.source retrievable via the value’s Tag (via Value::tag() or via the magic value Tagged) and Figment::get_metadata().

Variants (Non-exhaustive)

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.

File(PathBuf)

A file: the path to the file.

Code(&'static Location<'static>)

Some programatic value: the source location.

Custom(String)

A custom source all-together.

Implementations

Returns the path to the source file if self.kind is Kind::File.

Example
use std::path::Path;
use figment::Source;

let source = Source::from(Path::new("a/b/c.txt"));
assert_eq!(source.file_path(), Some(Path::new("a/b/c.txt")));

Returns the location to the source code if self is Source::Code.

Example
use std::panic::Location;

use figment::Source;

let location = Location::caller();
let source = Source::Code(location);
assert_eq!(source.code_location(), Some(location));

Returns the custom source location if self is Source::Custom.

Example
use figment::Source;

let source = Source::Custom("ftp://foo".into());
assert_eq!(source.custom(), Some("ftp://foo"));

Trait Implementations

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more

Displays the source. Location and custom sources are displayed directly. File paths are displayed relative to the current working directory if the relative path is shorter than the complete path.

Formats the value using the given formatter. Read more
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
Converts the given value to a String. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.