SkillMatch#

One skill condition of a Requirement: a skill id, a comparison and a value. A worker satisfies the match when worker value <op> value holds. Build one with SkillMatch::at_least, SkillMatch::no_more or SkillMatch::equal, or with a struct literal, and put it in Requirement::matches.

Declaration#

#[derive(Clone, Debug, PartialEq)]
pub struct SkillMatch {
    pub skill: Id,
    pub op: SkillOp,
    pub value: f64,
}

Fields#

Name Type Description
skill Id Id of the Skill to compare.
op SkillOp The comparison: >=, <= or ==, all inclusive.
value f64 The value the worker's skill value is compared with. Must be finite.

A worker without the skill has the value 0. So SkillMatch::at_least("qa", 1.0) excludes that worker, and SkillMatch::no_more("qa", 0.0) includes it.

A non-finite value is reported by slots as MatchError::Invalid at requirements[i].matches[j].value.

Associated functions#

at_least#

pub fn at_least(skill: impl Into<Id>, value: f64) -> SkillMatch

Creates a match that holds when the worker's skill value is >= value.

Name Type Description
skill impl Into<Id> Skill id.
value f64 Minimum value, inclusive.

Returns a SkillMatch with op: SkillOp::AtLeast.

no_more#

pub fn no_more(skill: impl Into<Id>, value: f64) -> SkillMatch

Creates a match that holds when the worker's skill value is <= value.

Name Type Description
skill impl Into<Id> Skill id.
value f64 Maximum value, inclusive.

Returns a SkillMatch with op: SkillOp::NoMore.

equal#

pub fn equal(skill: impl Into<Id>, value: f64) -> SkillMatch

Creates a match that holds when the worker's skill value is == value.

Name Type Description
skill impl Into<Id> Skill id.
value f64 Required value.

Returns a SkillMatch with op: SkillOp::Equal.

Example#

A requirement for a backend developer with a QA grade of at least 2 who isn't a trainee:

use plen_assign::{Requirement, SkillMatch, SkillOp};

fn main() {
    let review = Requirement::new(
        "review",
        "C",
        vec![
            SkillMatch::at_least("backend", 1.0),
            SkillMatch::at_least("qa", 2.0),
            SkillMatch::equal("trainee", 0.0),
        ],
    );

    // Same as SkillMatch::no_more("frontend", 1.0)
    let literal = SkillMatch { skill: "frontend".into(), op: SkillOp::NoMore, value: 1.0 };

    println!("{review:?} {literal:?}");
}
  • Requirement - holds the matches in its matches list
  • Skill - the worker value a match compares against
  • SkillOp - the comparison in op
  • slots - evaluates the matches to fill each slot's allowed list
  • Skills and Requirements - shows how to combine skill conditions in a requirement