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


# Worker

A resource that can be assigned, paired with its skill values. Workers go into [`Pool::workers`](<https://docs.dhtmlx.com/planning-engine/rust/api/assign/pool.md#workers>), which [`slots`](<https://docs.dhtmlx.com/planning-engine/rust/api/assign/slots.md>) reads. There's no constructor and no `Default`; build it with a struct literal.

## Declaration

```rust
#[derive(Clone, Debug, PartialEq)]
pub struct Worker {
    pub resource: Id,
    pub skills: Vec<Skill>,
}
```

## Fields

### resource

```rust
pub resource: Id
```

[`Id`](<https://docs.dhtmlx.com/planning-engine/rust/api/core/data/id.md>) of a resource in the project's accepted state. When the worker matches a requirement, this id goes into the slot's [`allowed`](<https://docs.dhtmlx.com/planning-engine/rust/api/core/suggest/slot.md>) list.

### skills

```rust
pub skills: Vec<Skill>
```

The worker's skill values, one [`Skill`](<https://docs.dhtmlx.com/planning-engine/rust/api/assign/skill.md>) per skill id. The list can be empty. For how an unlisted skill compares, see [`SkillMatch`](<https://docs.dhtmlx.com/planning-engine/rust/api/assign/skill-match.md>).

## Errors

An invalid worker makes [`slots`](<https://docs.dhtmlx.com/planning-engine/rust/api/assign/slots.md>) return `Err(`[`MatchError::Invalid`](<https://docs.dhtmlx.com/planning-engine/rust/api/assign/match-error.md>)`)` at the field's path, where `i` is the worker's index in the pool and `j` the skill's index.

| Field | When it occurs | Path | Message |
|---|---|---|---|
| `resource` | no resource with this id in the accepted state | `pool.workers[i].resource` | `unknown resource "<id>"` |
| `resource` | an earlier worker in the pool names the same resource | `pool.workers[i].resource` | `duplicate worker "<id>"` |
| `skills` | the worker already lists this skill id | `pool.workers[i].skills[j].id` | `duplicate skill "<id>"` |
| `skills` | the value is `NaN` or infinite | `pool.workers[i].skills[j].value` | `must be finite` |

## Example

```rust
use plen_assign::{Pool, Skill, Worker};

fn main() {
    let pool = Pool {
        workers: vec![
            Worker {
                resource: "ann".into(),
                skills: vec![
                    Skill { id: "frontend".into(), value: 1.0 },
                    Skill { id: "qa".into(), value: 2.0 },
                ],
            },
            // No skills: every skill counts as 0 for this worker.
            Worker { resource: "bob".into(), skills: vec![] },
        ],
    };
    println!("{} workers", pool.workers.len());
}
```

## Related

- [`Pool`](<https://docs.dhtmlx.com/planning-engine/rust/api/assign/pool.md>) - holds the workers in pool order
- [`Skill`](<https://docs.dhtmlx.com/planning-engine/rust/api/assign/skill.md>) - one entry of `skills`
- [`SkillMatch`](<https://docs.dhtmlx.com/planning-engine/rust/api/assign/skill-match.md>) - tests a worker's skill values
- [Skills and Requirements](<https://docs.dhtmlx.com/planning-engine/rust/resources-and-assignment/skills-and-requirements.md>) - shows how to describe workers and their skills
