declare_secrets!() { /* proc-macro */ }Expand description
Generates typed SecretSpec structs from your secretspec.toml file.
§Example
ⓘ
// In your main.rs or lib.rs:
secretspec_derive::declare_secrets!("secretspec.toml");
use secretspec::Provider;
fn main() -> Result<(), Box<dyn std::error::Error>> {
// Load with union types (safe for any profile) using the builder pattern
let secrets = SecretSpec::builder()
.with_provider(Provider::Keyring)
.load()?;
println!("Database URL: {}", secrets.secrets.database_url);
// Load with profile-specific types
let profile_secrets = SecretSpec::builder()
.with_provider(Provider::Keyring)
.with_profile(Profile::Production)
.load_profile()?;
match profile_secrets.secrets {
SecretSpecProfile::Production { api_key, database_url, .. } => {
println!("Production API key: {}", api_key);
}
_ => unreachable!(),
}
Ok(())
}