Comparison with serde
A side-by-side comparison of facet and serde derive macro attributes.
Container attributes
deny_unknown_fields
Rejects unknown fields during deserialization. By default, unknown fields are silently ignored.
| Facet | Serde |
|---|---|
|
rust
|
rust
|
default
Applies to structs only. Missing fields are filled from the type's Default implementation.
| Facet | Serde |
|---|---|
|
rust
|
rust
|
rename_all
Renames all fields using a casing convention. Supported values:
"PascalCase""camelCase""snake_case""SCREAMING_SNAKE_CASE""kebab-case""SCREAMING-KEBAB-CASE"
| Facet | Serde |
|---|---|
|
rust
|
rust
|
Field attributes
skip_serializing
Excludes this field from serialization.
| Facet | Serde |
|---|---|
|
rust
|
rust
|
skip_serializing_if
Conditionally excludes a field from serialization based on a predicate.
| Facet | Serde |
|---|---|
|
rust
|
rust
|
Facet accepts closures directly; serde requires a named function passed as a string.
skip_unless_truthy
Facet also provides skip_unless_truthy, which uses built-in truthiness predicates instead of requiring a custom function.
| Facet | Serde |
|---|---|
|
rust
|
rust
|
Truthiness is defined per type:
- Booleans:
falseis falsy - Numbers: zero is falsy (for floats, NaN is also falsy)
- Collections (
Vec,String, slices, etc.): empty is falsy - Option:
Noneis falsy
skip_all_unless_truthy (container attribute)
Applies skip_unless_truthy to all fields in the struct.
| Facet | Serde |
|---|---|
|
rust
|
rust
|
default
Provides a default value when deserializing a missing field. Can use Default::default() or a custom expression.
| Facet | Serde |
|---|---|
|
rust
|
rust
|
Facet accepts expressions directly; serde requires a function path as a string.
Implicit defaults
Facet implicitly defaults certain types when the field is absent:
Option<T>defaults toNoneVec<T>,HashMap<K, V>,HashSet<T>, and other collection types default to empty
| Facet | Serde |
|---|---|
|
rust
|
rust
|
This is a trade-off: facet cannot distinguish between "field absent" and "field present but empty" for these types. If that distinction matters, use a wrapper type or explicit handling.
Deriving Default
The facet-default crate provides a plugin for deriving Default using field-level #[facet(default = ...)] attributes.
| Facet | Rust stdlib |
|---|---|
|
rust
|
rust
|
For enums, mark the default variant with #[facet(default::variant)]:
# [ derive ( Facet , Debug )]
# [ facet ( derive ( Default ))]
# [ repr ( u8 )]
enum Status {
# [ facet ( default :: variant )]
Pending ,
Active ,
Done ,
}
let status = Status :: default (); // Status::Pending