pub struct Settings { /* private fields */ }Expand description
Parsed KEY=VALUE settings plus where they came from.
Implementations§
Source§impl Settings
impl Settings
Sourcepub fn from_pairs<K: Into<String>, V: Into<String>>(
pairs: impl IntoIterator<Item = (K, V)>,
) -> Self
pub fn from_pairs<K: Into<String>, V: Into<String>>( pairs: impl IntoIterator<Item = (K, V)>, ) -> Self
Fixed values with no environment fallback (tests, generated configs).
Sourcepub fn parse(text: &str) -> Result<Self>
pub fn parse(text: &str) -> Result<Self>
Parse settings text (see the module docs for the format).
Sourcepub fn locate(root: &Path) -> Result<Option<PathBuf>>
pub fn locate(root: &Path) -> Result<Option<PathBuf>>
The file Settings::discover would read for root, if any.
Sourcepub fn discover(root: &Path) -> Result<Self>
pub fn discover(root: &Path) -> Result<Self>
Load the first settings file in the documented search order; no file is not an error.
Sourcepub fn with_env_override(self, on: bool) -> Self
pub fn with_env_override(self, on: bool) -> Self
Enable or disable the process-environment override.
Sourcepub fn set(&mut self, key: impl Into<String>, value: impl Into<String>)
pub fn set(&mut self, key: impl Into<String>, value: impl Into<String>)
Set or replace one value (file-level; the environment still wins when enabled).
Sourcepub fn get(&self, key: &str) -> Option<String>
pub fn get(&self, key: &str) -> Option<String>
Non-empty value for key: process environment first (when enabled), then the file.
pub fn get_or(&self, key: &str, default: &str) -> String
Sourcepub fn require(&self, key: &str) -> Result<String>
pub fn require(&self, key: &str) -> Result<String>
Present or an error naming the key and the file.
Sourcepub fn parse_value<T: FromStr>(&self, key: &str) -> Result<Option<T>>
pub fn parse_value<T: FromStr>(&self, key: &str) -> Result<Option<T>>
Parsed value; Ok(None) when absent, an error when present but malformed.
Sourcepub fn get_bool(&self, key: &str) -> Result<Option<bool>>
pub fn get_bool(&self, key: &str) -> Result<Option<bool>>
1/true/yes/on or 0/false/no/off (case-insensitive); anything else is an error.
pub fn get_u64(&self, key: &str) -> Result<Option<u64>>
pub fn get_f64(&self, key: &str) -> Result<Option<f64>>
Sourcepub fn get_list(&self, key: &str) -> Vec<String>
pub fn get_list(&self, key: &str) -> Vec<String>
Comma-separated list, items trimmed, empties dropped.