#[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
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§
Source§impl Source
impl Source
Sourcepub fn file_path(&self) -> Option<&Path>
pub fn file_path(&self) -> Option<&Path>
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")));
Sourcepub fn code_location(&self) -> Option<&'static Location<'static>>
pub fn code_location(&self) -> Option<&'static Location<'static>>
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));
Trait Implementations§
Source§impl Display for Source
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.
impl Display for Source
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.
impl StructuralPartialEq for Source
Auto Trait Implementations§
impl Freeze for Source
impl RefUnwindSafe for Source
impl Send for Source
impl Sync for Source
impl Unpin for Source
impl UnwindSafe for Source
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Layout§
Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...)
attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.
Size: 32 bytes
Size for each variant:
File
: 24 bytesCode
: 8 bytesCustom
: 24 bytes