Patch#

A field of an update record that tells "leave as is" apart from "clear". Every field of TaskUpdate, LinkUpdate, ResourceUpdate and AssignmentUpdate, except id, is a Patch.

Declaration#

#[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.
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#

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#

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());
}