| Crates.io | sanar-idk |
| lib.rs | sanar-idk |
| version | 0.1.1 |
| created_at | 2025-10-06 18:50:25.728526+00 |
| updated_at | 2025-10-06 18:53:10.657439+00 |
| description | Initialize Default Keys - A Rust macro to generate config structs from environment variables easily |
| homepage | https://github.com/sanarberkebayram/idk |
| repository | https://github.com/sanarberkebayram/idk |
| max_upload_size | |
| id | 1870631 |
| size | 6,274 |
IDK is a simple Rust macro to generate configuration structs from environment variables.
It supports default values, required variables, and uses once_cell for lazy static access.
Add to Cargo.toml:
sanar-idk = "0.1.0"
use sanar-idk::create_config_struct;
create_config_struct! {
#[derive(Debug, Clone)]
pub struct Config {
pub port: u16 => "PORT", @default 8000,
pub db_url: String => "DATABASE_URL", @expect "DATABASE_URL must be set",
pub secret: String => "SECRET", @default "empty_secret".to_string()
}
}
fn main() {
println!("{:#?}", *Config::DEFAULT);
}
Features
Lazy initialization via once_cell::sync::Lazy
Support for dotenv files
Default values or required variables with custom error messages