Expand description
§value-extra
A tri-state Patch<T> type for partial update semantics.
§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:
Patch::Some(T)— set the field to this valuePatch::Empty— field was absent, leave unchangedPatch::None— field was explicitly null, clear it
§Quick Start
use value_extra::Patch;
fn apply_name_patch(current: &mut Option<String>, patch: Patch<String>) {
match patch {
Patch::Some(new) => *current = Some(new),
Patch::None => *current = None,
Patch::Empty => {}
}
}§Serde Usage
With the serde feature enabled:
ⓘ
#[derive(Deserialize, Serialize)]
struct UserPatch {
#[serde(default, skip_serializing_if = "Patch::is_empty")]
name: Patch<String>,
}| JSON Input | Patch State | Meaning |
|---|---|---|
{ "name": "Alice" } | Patch::Some("Alice") | Set to value |
{ "name": null } | Patch::None | Explicitly clear |
{ } | Patch::Empty | Leave unchanged |
Enums§
- Patch
- A tri-state type for partial update semantics.