Worker#

A resource that can be assigned, paired with its skill values. Workers go into Pool::workers, which slots reads. There's no constructor and no Default; build it with a struct literal.

Declaration#

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

Fields#

resource#

pub resource: Id

Id of a resource in the project's accepted state. When the worker matches a requirement, this id goes into the slot's allowed list.

skills#

pub skills: Vec<Skill>

The worker's skill values, one Skill per skill id. The list can be empty. For how an unlisted skill compares, see SkillMatch.

Errors#

An invalid worker makes slots return Err(MatchError::Invalid) 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#

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