dotenvy-derive-0.15.7 has been yanked.
dotenvy-derive
Proc macro that derives struct initialization from .env files at compile time via dotenv_codegen.
Usage
Add to Cargo.toml:
[]
= "0.15"
= "0.15"
impl Default (standard)
use Bind;
let config = default;
Generates:
pub const INSTANCE (static)
Add #[dotenv_static] to emit a compile-time constant instead:
use Bind;
// Use in const context:
pub const CONFIG: AppConfig = AppConfig ;
Generates:
Requirements
- All fields must be
&'static str—dotenv!returns&'static str - A
.envfile must exist at the crate root at build time - Consumer crate must depend on
dotenv_codegendirectly
Error handling
The macro emits a compile error for:
- Non-struct types (enums, unions)
- Tuple or unit structs
- Fields missing
#[dotenv("VAR_NAME")] - Malformed
#[dotenv(...)]attribute
License
MIT