pub struct ConfigLoader { /* private fields */ }Expand description
Configuration loader and parser
Implementations§
Source§impl ConfigLoader
impl ConfigLoader
Sourcepub fn from_str(content: &str) -> Result<GgenConfig>
pub fn from_str(content: &str) -> Result<GgenConfig>
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::ConfigLoader;
let toml = r#"
[project]
name = "my-project"
version = "1.0.0"
"#;
let config = ConfigLoader::from_str(toml).unwrap();
assert_eq!(config.project.name, "my-project");Sourcepub fn load(&self) -> Result<GgenConfig>
pub fn load(&self) -> Result<GgenConfig>
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>
pub fn find_and_load() -> Result<GgenConfig>
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::ConfigLoader;
// Searches current directory and parents for ggen.toml
let config = ConfigLoader::find_and_load()?;Sourcepub fn find_config_file() -> Result<PathBuf>
pub fn find_config_file() -> Result<PathBuf>
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>
pub fn load_with_env(&self, environment: &str) -> Result<GgenConfig>
Auto Trait Implementations§
impl Freeze for ConfigLoader
impl RefUnwindSafe for ConfigLoader
impl Send for ConfigLoader
impl Sync for ConfigLoader
impl Unpin 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