Skip to main content

Source

Struct Source 

Source
pub struct Source { /* private fields */ }
Expand description

One configuration source declaration.

A Source holds a loader name, its options, and an optional resource address, as parsed from the SOURCE[(OPTIONS)][:RESOURCE] string format. See the crate-level documentation for the full format, parsing rules, and examples.

§Examples

use tanzim_source::Source;

let source = Source::parse("env(prefix=APP_)")?;
assert_eq!(source.source(), "env");
assert_eq!(
    source.options().get("prefix").unwrap().as_string().unwrap(),
    "APP_"
);
assert_eq!(source.resource(), "");
assert_eq!(source.to_string(), "env(prefix=APP_)");

let file = Source::parse("file:app.toml")?;
assert_eq!(file.source(), "file");
assert_eq!(file.resource(), "app.toml");

Implementations§

Source§

impl Source

Source

pub fn parse(input: &str) -> Result<Source, ParseError>

Parse a SOURCE[(OPTIONS)][:RESOURCE] string into a Source.

Equivalent to the free function parse. See the crate-level documentation for the format and rules.

Source

pub fn named(name: impl Into<String>) -> Source

Build a bare source with just a name — no options, no resource — infallibly.

Used for synthetic origins (e.g. tanzim_value::Locations that do not come from parsing a real source string). Unlike Source::parse this performs no validation, so the name may even be empty for a placeholder origin.

Source

pub fn on_error(&self, stage: Stage) -> OnError

The error policy this source declares for stage, via its reserved on_error option.

Defaults to OnError::Fail when the option is absent, malformed, or does not mention the stage. on_error=(load=skip,validate=skip) yields OnError::Skip for those two stages.

Source

pub fn source(&self) -> &str

The loader name (e.g. env, file, http).

Source

pub fn source_mut(&mut self) -> &mut String

A mutable reference to the loader name.

Source

pub fn set_source(&mut self, source: impl Into<String>)

Set the loader name.

Source

pub fn with_source(self, source: impl Into<String>) -> Source

Set the loader name, builder-style.

Source

pub fn options(&self) -> &Options

The loader options.

Source

pub fn options_mut(&mut self) -> &mut Options

A mutable reference to the loader options.

Source

pub fn set_options(&mut self, options: Options)

Replace the loader options.

Source

pub fn with_options(self, options: Options) -> Source

Replace the loader options, builder-style.

Source

pub fn set_option<K, V>(&mut self, key: K, value: V)
where K: Into<String>, V: Into<OptionValue>,

Set a single loader option.

Source

pub fn with_option<K, V>(self, key: K, value: V) -> Source
where K: Into<String>, V: Into<OptionValue>,

Set a single loader option, builder-style.

Source

pub fn resource(&self) -> &str

The resource address (path, URL, …), or empty if none was given.

Source

pub fn resource_mut(&mut self) -> &mut String

A mutable reference to the resource address.

Source

pub fn set_resource(&mut self, resource: impl Into<String>)

Set the resource address; a non-empty value also sets Source::resource_colon.

Source

pub fn with_resource(self, resource: impl Into<String>) -> Source

Set the resource address, builder-style; a non-empty value also sets Source::resource_colon.

Source

pub fn resource_colon(&self) -> bool

true if the source string had a : separator before the resource, even when the resource itself is empty (e.g. file:).

Source

pub fn set_resource_colon(&mut self, resource_colon: bool)

Set whether the : separator is present before the resource.

Source

pub fn with_resource_colon(self, resource_colon: bool) -> Source

Set whether the : separator is present before the resource, builder-style.

Trait Implementations§

Source§

impl Clone for Source

Source§

fn clone(&self) -> Source

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 Debug for Source

Source§

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

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

impl Display for Source

Source§

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

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

impl FromStr for Source

Source§

type Err = ParseError

The associated error which can be returned from parsing.
Source§

fn from_str(value: &str) -> Result<Source, <Source as FromStr>::Err>

Parses a string s to return a value of this type. Read more
Source§

impl PartialEq for Source

Source§

fn eq(&self, other: &Source) -> 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 Source

Source§

impl TryFrom<&String> for Source

Source§

type Error = ParseError

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

fn try_from( value: &String, ) -> Result<Source, <Source as TryFrom<&String>>::Error>

Performs the conversion.
Source§

impl TryFrom<&str> for Source

Source§

type Error = ParseError

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

fn try_from(value: &str) -> Result<Source, <Source as TryFrom<&str>>::Error>

Performs the conversion.
Source§

impl TryFrom<Cow<'_, str>> for Source

Source§

type Error = ParseError

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

fn try_from( value: Cow<'_, str>, ) -> Result<Source, <Source as TryFrom<Cow<'_, str>>>::Error>

Performs the conversion.
Source§

impl TryFrom<String> for Source

Source§

type Error = ParseError

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

fn try_from(value: String) -> Result<Source, <Source as TryFrom<String>>::Error>

Performs the conversion.

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> 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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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