ConstraintType#

The scheduling constraint of a task. It's the type of TaskData::constraint_type and TaskUpdate::constraint_type, and conflicts report it in Conflict::ConstraintViolation. Constraints take effect only when SchedulingConfig::apply_constraints is true.

Declaration#

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ConstraintType {
    Asap,
    Alap,
    Snet,
    Snlt,
    Fnet,
    Fnlt,
    Mso,
    Mfo,
}

With the serde feature, ConstraintType implements Serialize and Deserialize and uses the lowercase names ("asap", "snet", ...).

Variants#

Variant Description
Asap As soon as possible. Places the task as early as its dependencies allow; no date.
Alap As late as possible. Places the task as late as its dependencies allow; no date.
Snet Start no earlier than the constraint date.
Snlt Start no later than the constraint date.
Fnet Finish no earlier than the constraint date.
Fnlt Finish no later than the constraint date.
Mso Must start on the constraint date.
Mfo Must finish on the constraint date.

All variants except Asap and Alap are dated: they need a constraint_date on the task. See TaskData.

Methods#

parse#

pub fn parse(s: &str) -> Option<ConstraintType>

Parses a constraint name. Matching ignores case, so "SNET" and "snet" both give ConstraintType::Snet.

Parameters

Name Type Description
s &str One of asap, alap, snet, snlt, fnet, fnlt, mso, mfo, in any case.

Returns - Some(ConstraintType), or None for any other string.

is_dated#

pub fn is_dated(&self) -> bool

Returns - true for the constraints that need a date (Snet, Snlt, Fnet, Fnlt, Mso, Mfo), false for Asap and Alap.

as_str#

pub fn as_str(&self) -> &'static str

Returns - the lowercase name of the variant, e.g. "mfo" for ConstraintType::Mfo. ConstraintType::parse accepts it back.

Example#

use plen_core::{ConstraintType, DateTime, TaskData};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let kind = ConstraintType::parse("SNET").ok_or("unknown constraint")?;
    assert!(kind.is_dated());
    assert_eq!(kind.as_str(), "snet");

    let mut task = TaskData::new(1);
    task.constraint_type = Some(kind);
    task.constraint_date = DateTime::from_ymd_hm(2026, 3, 2, 9, 0);
    Ok(())
}