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


# ResourceUpdate

An edit to one existing resource in a live project. It goes into `resources.update` of [`SchedulingChanges`](<https://docs.dhtmlx.com/planning-engine/rust/api/core/changes/scheduling-changes.md>), which [`Project::apply`](<https://docs.dhtmlx.com/planning-engine/rust/api/core/project/project.md#apply>) takes. Create it with `ResourceUpdate::new` and set only the fields to change. To add a resource, use [`ResourceData`](<https://docs.dhtmlx.com/planning-engine/rust/api/core/data/resource-data.md>) in `resources.add` instead.

## Declaration

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

## Constructors

### ResourceUpdate::new

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

Creates an update for the resource `id` with every field set to [`Patch::Missing`](<https://docs.dhtmlx.com/planning-engine/rust/api/core/changes/patch.md>), so nothing changes until a field is set.

**Parameters**

| Name | Type | Description |
|---|---|---|
| `id` | `impl Into<`[`Id`](<https://docs.dhtmlx.com/planning-engine/rust/api/core/data/id.md>)`>` | 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`](<https://docs.dhtmlx.com/planning-engine/rust/api/core/changes/patch.md>) rules: `Missing` leaves the field as is, `Null` clears it, `Value` sets it. The new value is validated like the matching [`ResourceData`](<https://docs.dhtmlx.com/planning-engine/rust/api/core/data/resource-data.md>) field.

### id

```rust
pub id: Id
```

[`Id`](<https://docs.dhtmlx.com/planning-engine/rust/api/core/data/id.md>) of the resource to edit. It must name a resource in the project.

### capacity

```rust
pub capacity: Patch<f64>
```

New [`ResourceData::capacity`](<https://docs.dhtmlx.com/planning-engine/rust/api/core/data/resource-data.md#capacity>). `Null` clears it, so the resource takes the default capacity again.

Default: `Patch::Missing`.

### calendar_id

```rust
pub calendar_id: Patch<Id>
```

New [`ResourceData::calendar_id`](<https://docs.dhtmlx.com/planning-engine/rust/api/core/data/resource-data.md#calendar_id>). `Null` clears it, so the resource has no calendar of its own. The id must name an existing calendar; [`Project::apply`](<https://docs.dhtmlx.com/planning-engine/rust/api/core/project/project.md#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](<https://docs.dhtmlx.com/planning-engine/rust/resources-and-assignment/resources-and-assignments.md>).

Default: `Patch::Missing`.

## Errors

[`Project::apply`](<https://docs.dhtmlx.com/planning-engine/rust/api/core/project/project.md#apply>) rejects the operation, and lists it under its path (such as `resources.update[0]`) in [`ApplyReport::rejected`](<https://docs.dhtmlx.com/planning-engine/rust/api/core/changes/apply-report.md#rejected>), when:

- `id` names no resource in the project (`unknown resource id`)
- the new `capacity` or `calendar_id` fails [`ResourceData` validation](<https://docs.dhtmlx.com/planning-engine/rust/api/core/data/resource-data.md#errors>)

A rejected update leaves the resource unchanged.

## Example

```rust
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(())
}
```

## Related

- [`ResourceData`](<https://docs.dhtmlx.com/planning-engine/rust/api/core/data/resource-data.md>) - the record an update edits
- [`Patch`](<https://docs.dhtmlx.com/planning-engine/rust/api/core/changes/patch.md>) - the type of every editable field
- [`ApplyReport`](<https://docs.dhtmlx.com/planning-engine/rust/api/core/changes/apply-report.md>) - reports whether the update was applied
- [Data Updates](<https://docs.dhtmlx.com/planning-engine/rust/live-projects/editing-a-project.md>) - shows resource updates in a change set
