value-extra
Extended value types for Rust — practical primitives beyond the standard library.
Installation
[]
= "0.1"
# With serde support
= { = "0.1", = ["serde"] }
Types
Patch<T>
A tri-state type for partial update semantics — distinguishing between "has value", "absent", and "explicitly null".
The Problem
When handling partial updates (PATCH requests, config merging, etc.), Option<T> conflates two distinct states:
- Field is absent → don't touch the existing value
- Field is explicitly null → clear/reset the value
The Solution
Patch<T> provides three states:
| JSON Input | Patch State | Meaning |
|---|---|---|
{ "name": "Alice" } |
Patch::Some("Alice") |
Set to value |
{ "name": null } |
Patch::None |
Explicitly clear |
{ } |
Patch::Empty |
Leave unchanged |
use Patch;
Features
- Option-like API —
map,and_then,unwrap_or,filter,zip, and more - Serde support — feature-gated serialization with tri-state JSON handling
- no_std compatible — works in embedded and WASM environments
See the full documentation for API details and serde usage examples.
License
MIT — see LICENSE for details.