pub struct Config { /* private fields */ }Expand description
A configuration holder that loads from TOML and allows environment overrides.
Implementations§
Source§impl Config
impl Config
Sourcepub fn from_toml(content: &str) -> Result<Self, ConfigError>
pub fn from_toml(content: &str) -> Result<Self, ConfigError>
Loads configuration values from TOML content.
Sourcepub fn from_file(path: &Path) -> Result<Self, ConfigError>
pub fn from_file(path: &Path) -> Result<Self, ConfigError>
Loads configuration values from a TOML file.
Sourcepub fn get_str(&self, key: &str) -> Option<&str>
pub fn get_str(&self, key: &str) -> Option<&str>
Returns a string configuration value by dotted path.
Sourcepub fn get_i64(&self, key: &str) -> Option<i64>
pub fn get_i64(&self, key: &str) -> Option<i64>
Returns an integer configuration value by dotted path.
Sourcepub fn get_bool(&self, key: &str) -> Option<bool>
pub fn get_bool(&self, key: &str) -> Option<bool>
Returns a boolean configuration value by dotted path.
Sourcepub fn set(&mut self, key: impl Into<String>, value: Value)
pub fn set(&mut self, key: impl Into<String>, value: Value)
Sets a configuration value by dotted path, creating nested objects as needed.
Sourcepub fn apply_env_overrides(&mut self, prefix: &str)
pub fn apply_env_overrides(&mut self, prefix: &str)
Applies environment variable overrides using the provided prefix.
APP_DATABASE_HOST becomes the dotted key database.host.
Sourcepub fn extract<T: DeserializeOwned>(&self) -> Result<T, ConfigError>
pub fn extract<T: DeserializeOwned>(&self) -> Result<T, ConfigError>
Deserializes the configuration into a typed structure.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Config
impl RefUnwindSafe for Config
impl Send for Config
impl Sync for Config
impl Unpin for Config
impl UnsafeUnpin for Config
impl UnwindSafe for Config
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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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>
Converts
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>
Converts
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 more