ResourceUpdate#

An edit to one existing resource in a live project. It goes into resources.update of SchedulingChanges, which Project::apply takes. Create it with ResourceUpdate::new and set only the fields to change. To add a resource, use ResourceData in resources.add instead.

Declaration#

#[derive(Clone, Debug)]
pub struct ResourceUpdate {
    pub id: Id,
    pub capacity: Patch<f64>,
    pub calendar_id: Patch<Id>,
}

Constructors#

ResourceUpdate::new#

pub fn new(id: impl Into<Id>) -> ResourceUpdate

Creates an update for the resource id with every field set to Patch::Missing, so nothing changes until a field is set.

Parameters

Name Type Description
id impl Into<Id> Id of the resource to edit. Accepts a string or a number.

Returns a ResourceUpdate that leaves the resource unchanged.

Fields#

Each Patch field follows the Patch rules: Missing leaves the field as is, Null clears it, Value sets it. The new value is validated like the matching ResourceData field.

id#

pub id: Id

Id of the resource to edit. It must name a resource in the project.

capacity#

pub capacity: Patch<f64>

New ResourceData::capacity. Null clears it, so the resource takes the default capacity again.

Default: Patch::Missing.

calendar_id#

pub calendar_id: Patch<Id>

New ResourceData::calendar_id. Null clears it, so the resource has no calendar of its own. The id must name an existing calendar; Project::apply can't add calendars.

When assignments work on resource calendars, a task whose working calendars change keeps its start and duration, and its end is derived again. See Resources and assignments.

Default: Patch::Missing.

Errors#

Project::apply rejects the operation, and lists it under its path (such as resources.update[0]) in ApplyReport::rejected, when:

  • id names no resource in the project (unknown resource id)
  • the new capacity or calendar_id fails ResourceData validation

A rejected update leaves the resource unchanged.

Example#

use plen_core::{
    Patch, Project, ProjectData, ProjectOptions, ResourceData, ResourceUpdate,
    SchedulingChanges, SolveOptions,
};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let mut project = Project::new(ProjectOptions::default());
    let data = ProjectData {
        resources: vec![ResourceData {
            id: "team".into(),
            capacity: Some(1.0),
            calendar_id: None,
        }],
        ..Default::default()
    };
    project.solve(Some(data), &SolveOptions::default())?;

    let mut update = ResourceUpdate::new("team");
    update.capacity = Patch::Value(2.0);

    let mut changes = SchedulingChanges::default();
    changes.resources.update.push(update);

    let report = project.apply(&changes)?;
    println!("rejected: {:?}", report.rejected);
    Ok(())
}