confide
#[confide] is a proc-macro for config structs: generates Default + Debug with serde defaults in one attribute.
Quick Start
use confide;
use Duration;
This generates Default, Debug, and per-field #[serde(default = ...)] so missing keys in config files are filled in automatically.
Macro Arguments
| Argument | Effect |
|---|---|
| (none) | Generates both Default and Debug |
no_default |
Suppresses impl Default |
no_debug |
Suppresses impl Debug |
Combine freely: #[confide(no_default, no_debug)].
Field Annotations
#[confide(default)]
Use the type's Default::default(). Adds #[serde(default)].
#[confide(default = expr)]
Use the given Rust expression. If the expression is a bare path (e.g. Vec::new), serde calls it directly. Otherwise a hidden helper function is generated.
pub allowed_ports: ,
pub retries: u32,
#[confide(default_duration = "...")]
Parse a humantime duration string at compile time. The field type should be std::time::Duration. The generated code also adds #[serde(with = "confide::humantime_serde")] so durations serialize as human-readable strings like "5m" / "2h".
pub heartbeat: Duration,
#[confide(default_bytes = "...")]
Parse a bytesize string at compile time. The field should be an integer type (u64, u32, usize, etc.). Serialization produces IEC-formatted strings (e.g. "1 MiB"); deserialization accepts both raw integers and strings like "500 KB" / "2 GiB".
pub max_size: u64,
#[confide(secret)]
Masks the field in Debug output (shows "***"). The field is still serialized/deserialized normally.
pub api_key: String,
Multiple annotations can be combined: #[confide(default_bytes = "1 MiB", secret)].
Requirements
- Named fields only. Tuple structs and unit structs are not supported.
- Every field needs a default annotation unless you pass
no_defaultto the macro. Without it the generatedDefaultimpl will be incomplete. - The
serdecrate must be in scope (as a dependency of your crate) for#[serde(...)]attributes to resolve. - The
confidecrate must be in your dependencies for generated code referencesconfide::humantime_serdeandconfide::bytesize::ByteSizeat runtime.
License
Licensed under either of Apache License 2.0 or MIT license at your option.