dotenvy-derive
Proc macro that derives struct initialization from .env files at compile time via dotenvy_macro.
Usage
Add to Cargo.toml:
[]
= "0.15"
= "0.15"
impl Default (standard)
use Bind;
let config = default;
Generates:
pub const INSTANCE (static)
Add #[env_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
dotenvy_macrodirectly
Error handling
The macro emits a compile error for:
- Non-struct types (enums, unions)
- Tuple or unit structs
- Fields missing
#[env("VAR_NAME")] - Malformed
#[env(...)]attribute
License
MIT