| Crates.io | envman |
| lib.rs | envman |
| version | 2.0.0 |
| created_at | 2024-08-30 15:08:52.970922+00 |
| updated_at | 2025-08-17 06:51:59.722625+00 |
| description | Rust crates to manage environment variables. |
| homepage | |
| repository | https://github.com/moriyoshi-kasuga/envman |
| max_upload_size | |
| id | 1357777 |
| size | 15,197 |
EnvMan is a Rust crate that provides a procedural macro to simplify the management of environment variables. It allows you to automatically load and parse environment variables into your Rust structs, with support for default values, custom parsers, and more.
rename_all, prefix, and suffix to control environment variable naming.Here's a basic example demonstrating how to use EnvMan to manage environment variables:
use envman::EnvMan;
use std::net::IpAddr;
#[derive(EnvMan)]
struct Config {
#[envman(rename = "APP_PORT", test = 8080)]
port: u16,
#[envman(nest)]
database: DatabaseConfig,
}
#[derive(EnvMan)]
#[envman(prefix = "DB_",)]
struct DatabaseConfig {
#[envman(default = "127.0.0.1")]
host: IpAddr,
#[envman(default = 5432)]
port: u16,
}
// NOTE: This is for demonstration purposes only in README.
// In real applications, set environment variables through your system or .env files.
#[allow(unused_unsafe)]
unsafe {
std::env::set_var("APP_PORT", "5000");
std::env::set_var("DB_HOST", "192.168.1.1");
std::env::set_var("DB_PORT", "5432");
}
// Load the configuration from environment variables
let config = Config::load_from_env().expect("Failed to load configuration");
// Assertions to verify the configuration
assert_eq!(config.port, 5000);
assert_eq!(config.database.host.to_string(), "192.168.1.1");
assert_eq!(config.database.port, 5432);
rename_all: Apply a naming convention to all fields (default: SCREAMING_SNAKE_CASE).prefix: Add a prefix to all field names.suffix: Add a suffix to all field names.rename: Specify a custom environment variable name for a field.default: Provide a default value if the environment variable is not set.parser: Use a custom parser function to parse the environment variable. (default: FromStr::from_str)nest: Indicate that the field is a nested struct implementing EnvMan.more info: doc.rs
Licensed under