pub struct ConfigLoader;Expand description
Configuration file loader
Implementations§
Source§impl ConfigLoader
impl ConfigLoader
Sourcepub fn load_file<P: AsRef<Path>>(path: P) -> ConfigResult<BackboneConfig>
pub fn load_file<P: AsRef<Path>>(path: P) -> ConfigResult<BackboneConfig>
Load configuration from a file
Automatically detects format from file extension:
.yml,.yaml→ YAML.toml→ TOML.json→ JSON
Environment variables in ${VAR} or ${VAR:default} format
are substituted before parsing.
Sourcepub fn load_with_env<P: AsRef<Path>>(
base_path: P,
env: &str,
) -> ConfigResult<BackboneConfig>
pub fn load_with_env<P: AsRef<Path>>( base_path: P, env: &str, ) -> ConfigResult<BackboneConfig>
Load configuration with environment-specific overrides
- Loads base config from
{base_path} - If
{base_path}-{env}.{ext}exists, merges it
§Example
ⓘ
// Loads config/application.yml
// Then merges config/application-production.yml if it exists
let config = ConfigLoader::load_with_env("config/application.yml", "production")?;Sourcepub fn substitute_env_vars(content: &str) -> ConfigResult<String>
pub fn substitute_env_vars(content: &str) -> ConfigResult<String>
Substitute environment variables in configuration content
Supports two formats:
${VAR}- Required variable, fails if not set${VAR:default}- Optional variable with default value
§Example
ⓘ
let content = "url: ${DATABASE_URL:postgresql://localhost/db}";
let result = ConfigLoader::substitute_env_vars(content)?;Sourcepub fn from_yaml_str(content: &str) -> ConfigResult<BackboneConfig>
pub fn from_yaml_str(content: &str) -> ConfigResult<BackboneConfig>
Load configuration from a string
Useful for testing or embedded configs.
Sourcepub fn from_toml_str(content: &str) -> ConfigResult<BackboneConfig>
pub fn from_toml_str(content: &str) -> ConfigResult<BackboneConfig>
Load configuration from a string (TOML format)
Sourcepub fn from_json_str(content: &str) -> ConfigResult<BackboneConfig>
pub fn from_json_str(content: &str) -> ConfigResult<BackboneConfig>
Load configuration from a string (JSON format)
Auto Trait Implementations§
impl Freeze for ConfigLoader
impl RefUnwindSafe for ConfigLoader
impl Send for ConfigLoader
impl Sync for ConfigLoader
impl Unpin for ConfigLoader
impl UnsafeUnpin for ConfigLoader
impl UnwindSafe for ConfigLoader
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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