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
impl Source
Sourcepub fn parse(input: &str) -> Result<Self, ParseError>
pub fn parse(input: &str) -> Result<Self, 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.
Sourcepub fn named(name: impl Into<String>) -> Self
pub fn named(name: impl Into<String>) -> Self
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.
Sourcepub fn on_error(&self, stage: Stage) -> OnError
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.
Sourcepub fn source_mut(&mut self) -> &mut String
pub fn source_mut(&mut self) -> &mut String
A mutable reference to the loader name.
Sourcepub fn set_source(&mut self, source: impl Into<String>)
pub fn set_source(&mut self, source: impl Into<String>)
Set the loader name.
Sourcepub fn with_source(self, source: impl Into<String>) -> Self
pub fn with_source(self, source: impl Into<String>) -> Self
Set the loader name, builder-style.
Sourcepub fn options_mut(&mut self) -> &mut Options
pub fn options_mut(&mut self) -> &mut Options
A mutable reference to the loader options.
Sourcepub fn set_options(&mut self, options: Options)
pub fn set_options(&mut self, options: Options)
Replace the loader options.
Sourcepub fn with_options(self, options: Options) -> Self
pub fn with_options(self, options: Options) -> Self
Replace the loader options, builder-style.
Sourcepub fn set_option<K: Into<String>, V: Into<OptionValue>>(
&mut self,
key: K,
value: V,
)
pub fn set_option<K: Into<String>, V: Into<OptionValue>>( &mut self, key: K, value: V, )
Set a single loader option.
Sourcepub fn with_option<K: Into<String>, V: Into<OptionValue>>(
self,
key: K,
value: V,
) -> Self
pub fn with_option<K: Into<String>, V: Into<OptionValue>>( self, key: K, value: V, ) -> Self
Set a single loader option, builder-style.
Sourcepub fn resource(&self) -> &str
pub fn resource(&self) -> &str
The resource address (path, URL, …), or empty if none was given.
Sourcepub fn resource_mut(&mut self) -> &mut String
pub fn resource_mut(&mut self) -> &mut String
A mutable reference to the resource address.
Sourcepub fn set_resource(&mut self, resource: impl Into<String>)
pub fn set_resource(&mut self, resource: impl Into<String>)
Set the resource address; a non-empty value also sets Source::resource_colon.
Sourcepub fn with_resource(self, resource: impl Into<String>) -> Self
pub fn with_resource(self, resource: impl Into<String>) -> Self
Set the resource address, builder-style; a non-empty value also sets
Source::resource_colon.
Sourcepub fn resource_colon(&self) -> bool
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:).
Sourcepub fn set_resource_colon(&mut self, resource_colon: bool)
pub fn set_resource_colon(&mut self, resource_colon: bool)
Set whether the : separator is present before the resource.
Sourcepub fn with_resource_colon(self, resource_colon: bool) -> Self
pub fn with_resource_colon(self, resource_colon: bool) -> Self
Set whether the : separator is present before the resource, builder-style.