LoadProfileOptions#

Options passed to Project::load_profile: a ProfileQuery and an optional expected baseline token. LoadProfileOptions has no Default. Build it from a query with From<ProfileQuery> (query.into()), or as a struct literal when baseline_id is set.

Declaration#

#[derive(Clone, Debug)]
pub struct LoadProfileOptions {
    pub query: ProfileQuery,
    pub baseline_id: Option<String>,
}

impl From<ProfileQuery> for LoadProfileOptions

Fields#

Field Type Default Description
query ProfileQuery required Date range, resources, basis and task lists the profile covers.
baseline_id Option<String> None Expected baseline token. Some makes the call fail with ProjectError::StaleBaseline unless it names the current baseline. Take it from the latest ScheduleResult's baseline_id. None skips the check.

Example#

use plen_core::{
    AssignmentData, DateTime, LoadProfileOptions, ProfileQuery, Project, ProjectData,
    ResourceData, SolveOptions, TaskData,
};

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

    let mut task = TaskData::new("a");
    task.start_date = Some(day(5)?);
    task.duration = Some(2.0);

    let data = ProjectData {
        tasks: vec![task],
        resources: vec![ResourceData { id: "r1".into(), capacity: None, calendar_id: None }],
        assignments: vec![AssignmentData {
            id: None,
            task: "a".into(),
            resource: "r1".into(),
            value: 1.0,
            offset: None,
            duration: None,
        }],
        ..Default::default()
    };

    let mut project = Project::default();
    let solved = project.solve(Some(data), &SolveOptions::default())?;

    let options = LoadProfileOptions {
        query: ProfileQuery::new(day(5)?, day(10)?),
        baseline_id: solved.baseline_id.clone(),
    };
    let profile = project.load_profile(&options)?;
    for resource in &profile.resources {
        for bucket in &resource.buckets {
            println!("{:?} {:?}: {} / {}", resource.resource, bucket.start, bucket.load, bucket.capacity);
        }
    }

    // Without a baseline check, convert the query directly.
    let _ = project.load_profile(&ProfileQuery::new(day(5)?, day(10)?).into())?;
    Ok(())
}