1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
//! # CFGLoader
//!
//! A simple, powerful, and ergonomic configuration loading library for Rust applications.
//!
//! CFGLoader automatically loads configuration from environment variables and `.env` files
//! with compile-time validation and type safety.
//!
//! ## Installation
//!
//! Add this to your `Cargo.toml`:
//!
//! ```toml
//! [dependencies]
//! cfgloader_rs = "0.1"
//! ```
//!
//! ## Quick Start
//!
//! ### Basic Usage
//!
//! ```rust,no_run
//! use cfgloader_rs::*;
//!
//! #[derive(FromEnv, Debug)]
//! struct Config {
//! #[env("DATABASE_URL", default = "sqlite://app.db")]
//! database_url: String,
//!
//! #[env("PORT", default = "8080")]
//! port: u16,
//!
//! #[env("API_KEY", required)]
//! api_key: String,
//!
//! #[env("FEATURES", default = "auth,logging", split = ",")]
//! features: Vec<String>,
//! }
//!
//! fn main() -> Result<(), Box<dyn std::error::Error>> {
//! let config = Config::load(std::path::Path::new(".env"))?;
//! println!("Config: {:#?}", config);
//! Ok(())
//! }
//! ```
//!
//! ### Nested Configuration
//!
//! Organize your configuration into logical groups:
//!
//! ```rust,no_run
//! use cfgloader_rs::*;
//!
//! #[derive(FromEnv, Debug)]
//! struct AppConfig {
//! #[env("APP_NAME", required)]
//! name: String,
//!
//! // Nested structs automatically call their own load() method
//! server: ServerConfig,
//! database: DatabaseConfig,
//! }
//!
//! #[derive(FromEnv, Debug)]
//! struct ServerConfig {
//! #[env("SERVER_HOST", default = "127.0.0.1")]
//! host: String,
//!
//! #[env("SERVER_PORT", default = "8080")]
//! port: u16,
//! }
//!
//! #[derive(FromEnv, Debug)]
//! struct DatabaseConfig {
//! #[env("DB_URL", required)]
//! url: String,
//!
//! #[env("DB_MAX_CONNECTIONS", default = "10")]
//! max_connections: u32,
//! }
//!
//! fn main() -> Result<(), Box<dyn std::error::Error>> {
//! let config = AppConfig::load(std::path::Path::new(".env"))?;
//!
//! println!("App: {}", config.name);
//! println!("Server: {}:{}", config.server.host, config.server.port);
//! println!("Database: {}", config.database.url);
//!
//! Ok(())
//! }
//! ```
// Re-export all core functionality
pub use *;
// Re-export derive macro when derive feature is enabled
pub use FromEnv;