schedule#

Schedules a ProjectData snapshot once and returns the result. The call is stateless: it's equivalent to Project::default().solve(Some(data), options) on a temporary Project that's dropped when the call returns. Nothing is kept between calls.

Signature#

pub fn schedule(data: ProjectData, options: &SolveOptions) -> Result<ScheduleResult, Error>

Synchronous and CPU-only. The same data and options always produce the same result.

Parameters#

Name Type Description
data ProjectData The full snapshot to schedule. Taken by value.
options &SolveOptions What to schedule and what to report. &SolveOptions::default() schedules the whole project.

data is always validated with Validation::Strict.

Returns#

Ok(ScheduleResult), returned by value.

The result's baseline_id is set, but it names the baseline of the temporary project, so no later call can use it.

Errors#

Error When it occurs
Error::Input data fails strict validation; see InputError. The rules are listed on ProjectData.

schedule never returns Error::Project: each call starts from a fresh project.

Example#

use plen_core::{schedule, DateTime, LinkData, LinkType, ProjectData, SolveOptions, TaskData};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let monday = DateTime::from_ymd_hm(2026, 1, 5, 8, 0).ok_or("invalid date")?;

    let mut design = TaskData::new("design");
    design.start_date = Some(monday);
    design.duration = Some(2.0);

    let mut build = TaskData::new("build");
    build.start_date = Some(monday);
    build.duration = Some(3.0);

    let data = ProjectData {
        tasks: vec![design, build],
        links: vec![LinkData {
            id: "l1".into(),
            source: "design".into(),
            target: "build".into(),
            link_type: LinkType::Fs,
            lag: 0.0,
            lag_unit: None,
        }],
        ..Default::default()
    };

    let result = schedule(data, &SolveOptions::default())?;

    for update in &result.updates {
        if let (Some(start), Some(end)) = (update.start_date, update.end_date) {
            println!("{}: {} - {}", update.id, start, end);
        }
    }
    Ok(())
}