facet-default
facet-default
Derive Default for your types using facet's plugin system with custom field defaults.
Usage
use Facet;
use facet_default as default;
Attributes
Field Level
#[facet(default::value = literal)]- Use a literal value (converted via.into())#[facet(default::func = "path")]- Call a function to get the default value
Fields without attributes use Default::default().
Note: For numeric literals, use type suffixes to ensure correct types (e.g., 8080u16 instead of 8080 for a u16 field). String literals are automatically converted via .into().
Enums
For enums, mark the default variant with #[facet(default::variant)]:
use Facet;
use facet_default as default;
assert_eq!;
Enum variants with fields also work - fields use their own default attributes:
use Facet;
use facet_default as default;
LLM contribution policy
Sponsors
Thanks to all individual sponsors:
...along with corporate sponsors:
...without whom this work could not exist.
Special thanks
The facet logo was drawn by Misiasart.
License
Licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.