ConfigLoader

Struct ConfigLoader 

Source
pub struct ConfigLoader { /* private fields */ }
Expand description

Configuration loader and parser

Implementations§

Source§

impl ConfigLoader

Source

pub fn new<P: AsRef<Path>>(path: P) -> Result<Self>

Create a new config loader from a file path

§Arguments
  • path - Path to the ggen.toml file
§Errors

Returns an error if the file doesn’t exist

Source

pub fn from_file<P: AsRef<Path>>(path: P) -> Result<GgenConfig>

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::ConfigLoader;

let config = ConfigLoader::from_file("ggen.toml")?;
println!("Loaded project: {}", config.project.name);
Source

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");
Source

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

Source

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()?;
Source

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

Source

pub fn load_with_env(&self, environment: &str) -> Result<GgenConfig>

Load configuration with environment-specific overrides

§Arguments
  • environment - Environment name (e.g., “development”, “production”)
§Errors

Returns an error if the file cannot be read or parsed

Source

pub fn path(&self) -> &Path

Get the config file path

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.