[Canonical page](<https://docs.dhtmlx.com/planning-engine/rust/api/core/changes/patch/>)
[Full documentation index](<https://docs.dhtmlx.com/planning-engine/llms.txt>)


# Patch

A field of an update record that tells "leave as is" apart from "clear". Every field of [`TaskUpdate`](<https://docs.dhtmlx.com/planning-engine/rust/api/core/changes/task-update.md>), [`LinkUpdate`](<https://docs.dhtmlx.com/planning-engine/rust/api/core/changes/link-update.md>), [`ResourceUpdate`](<https://docs.dhtmlx.com/planning-engine/rust/api/core/changes/resource-update.md>) and [`AssignmentUpdate`](<https://docs.dhtmlx.com/planning-engine/rust/api/core/changes/assignment-update.md>), except `id`, is a `Patch`.

## Declaration

```rust
#[derive(Clone, Debug, Default, PartialEq)]
pub enum Patch<T> {
    #[default]
    Missing,
    Null,
    Value(T),
}
```

## Variants

| Variant | Description |
|---|---|
| `Missing` | The field isn't touched. Default. |
| `Null` | Clears the field. An optional field becomes empty; a field with a default value goes back to that default. On a required field (such as a link's `source` or an assignment's `resource`), the operation is rejected with a validation [`InputError`](<https://docs.dhtmlx.com/planning-engine/rust/api/core/errors/input-error.md>). |
| `Value(T)` | Sets the field to the given value. |

Which fields are optional, which have defaults and which are required is listed on each update record's page.

## Methods

### Patch::is_missing

```rust
pub fn is_missing(&self) -> bool
```

**Returns** `true` for `Patch::Missing`, `false` for `Null` and `Value`.

## Serde

With the `serde` feature, `Patch<T>` implements `Serialize` and `Deserialize` when `T` does:

- `Value(v)` serializes as `v`; `Missing` and `Null` both serialize as `null`
- `null` deserializes to `Null`, any other value to `Value`. Deserialization never produces `Missing`

## Example

```rust
use plen_core::{Patch, TaskUpdate};

fn main() {
    let mut update = TaskUpdate::new(1);
    update.duration = Patch::Value(3.0); // set
    update.constraint_date = Patch::Null; // clear

    assert!(update.start_date.is_missing()); // left as is
    assert!(!update.duration.is_missing());
}
```

## Related

- [`SchedulingChanges`](<https://docs.dhtmlx.com/planning-engine/rust/api/core/changes/scheduling-changes.md>) - carries the update records whose fields are patches
- [Data Updates](<https://docs.dhtmlx.com/planning-engine/rust/live-projects/editing-a-project.md>) - shows update records and `Patch` values together
- [Clear leveling](<https://docs.dhtmlx.com/planning-engine/rust/how-to/clear-leveling.md>) - uses `Patch` values to reset leveling fields
