pub struct ConfigLoader { /* private fields */ }Expand description
Configuration loader and parser
Implementations§
Source§impl ConfigLoader
impl ConfigLoader
Sourcepub fn new<P>(path: P) -> Result<ConfigLoader, ConfigError>
pub fn new<P>(path: P) -> Result<ConfigLoader, ConfigError>
Sourcepub fn from_file<P>(path: P) -> Result<GgenConfig, ConfigError>
pub fn from_file<P>(path: P) -> Result<GgenConfig, ConfigError>
Load and parse configuration from a file
§Arguments
path- Path to the ggen.toml file
§Errors
Returns an error if the file cannot be read or parsed
§Example
use ggen_config::config_lib::ConfigLoader;
let config = ConfigLoader::from_file("ggen.toml")?;
println!("Loaded project: {}", config.project.name);Sourcepub fn from_str(content: &str) -> Result<GgenConfig, ConfigError>
pub fn from_str(content: &str) -> Result<GgenConfig, ConfigError>
Load and parse configuration from a string
§Arguments
content- TOML content as a string
§Errors
Returns an error if the TOML cannot be parsed
§Example
use ggen_config::config_lib::ConfigLoader;
let toml = r#"
[project]
name = "my-project"
version = "1.0.0"
"#;
let config = ConfigLoader::from_str(toml)?;
assert_eq!(config.project.name, "my-project");Sourcepub fn load(&self) -> Result<GgenConfig, ConfigError>
pub fn load(&self) -> Result<GgenConfig, ConfigError>
Load configuration from the stored file path
§Errors
Returns an error if the file cannot be read or parsed
Sourcepub fn find_and_load() -> Result<GgenConfig, ConfigError>
pub fn find_and_load() -> Result<GgenConfig, ConfigError>
Find and load ggen.toml from current or parent directories
Searches upward through the directory tree until finding ggen.toml or reaching the filesystem root.
§Errors
Returns an error if no ggen.toml is found or if it cannot be parsed
§Example
use ggen_config::config_lib::ConfigLoader;
// Searches current directory and parents for ggen.toml
let config = ConfigLoader::find_and_load()?;Sourcepub fn find_config_file() -> Result<PathBuf, ConfigError>
pub fn find_config_file() -> Result<PathBuf, ConfigError>
Find ggen.toml by searching current and parent directories
§Errors
Returns an error if no configuration file is found
Sourcepub fn load_with_env(
&self,
environment: &str,
) -> Result<GgenConfig, ConfigError>
pub fn load_with_env( &self, environment: &str, ) -> Result<GgenConfig, ConfigError>
Sourcepub fn load_with_env_from_map(
self,
overrides: &[(&str, Value)],
) -> Result<GgenConfig, ConfigError>
pub fn load_with_env_from_map( self, overrides: &[(&str, Value)], ) -> Result<GgenConfig, ConfigError>
Load configuration with environment-specific overrides from a map
§Arguments
overrides- Slice of (environment_name, overrides) tuples
§Errors
Returns an error if the config cannot be loaded
§Example
use ggen_config::config_lib::ConfigLoader;
use serde_json::json;
let loader = ConfigLoader::new("ggen.toml")?;
let config = loader.load_with_env_from_map(&[("zai", json!({"ai.provider": "zai"}))])?;
assert_eq!(config.ai.map(|a| a.provider), Some("zai".to_string()));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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> EvidenceKind for T
impl<T> EvidenceKind for T
default fn kind_label(&self) -> &'static str
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> ⓘ
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> ⓘ
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