[Canonical page](<https://docs.dhtmlx.com/planning-engine/rust/api/core/resources/capacity-mode/>)
[Full documentation index](<https://docs.dhtmlx.com/planning-engine/llms.txt>)


# CapacityMode

Tells how a resource's capacity is spread over the buckets of a load profile. It's the type of [`ResourceLoad::capacity_mode`](<https://docs.dhtmlx.com/planning-engine/rust/api/core/resources/resource-load.md>), returned by [`Project::load_profile`](<https://docs.dhtmlx.com/planning-engine/rust/api/core/project/project.md#load_profile>). The mode decides the `capacity` value of every [`LoadBucket`](<https://docs.dhtmlx.com/planning-engine/rust/api/core/resources/load-bucket.md>) of that resource.

## Declaration

```rust
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum CapacityMode {
    Calendar,
    Flat,
}
```

With the `serde` feature, the variants serialize as `"calendar"` and `"flat"`.

## Variants

| Variant | Description |
|---|---|
| `Calendar` | Capacity follows the resource's calendar: buckets with working time on that calendar get the resource's capacity, all others get 0. Reported when the resource has a calendar, `config.calendar_mode` is [`CalendarMode::Resource`](<https://docs.dhtmlx.com/planning-engine/rust/api/core/data/calendar-mode.md>) and `config.use_calendars` is `true`. |
| `Flat` | Every bucket gets the resource's capacity, non-working time included. Reported in all other cases: no resource calendar, a task calendar mode, or `use_calendars: false`. |

The capacity value itself is [`ResourceData::capacity`](<https://docs.dhtmlx.com/planning-engine/rust/api/core/data/resource-data.md#capacity>). The calendar setting lives in [`SchedulingConfig`](<https://docs.dhtmlx.com/planning-engine/rust/api/core/data/scheduling-config.md>).

## Example

```rust
use plen_core::{
    CalendarData, CapacityMode, DateTime, ProfileQuery, Project, ProjectData, ResourceData,
    SolveOptions, TaskData, Worktime,
};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    // 2026-08-10 is a Monday.
    let monday = DateTime::from_ymd_hm(2026, 8, 10, 8, 0).ok_or("invalid date")?;
    let mut task = TaskData::new("a");
    task.start_date = Some(monday);
    task.duration = Some(1.0);

    let data = ProjectData {
        tasks: vec![task],
        calendars: vec![CalendarData {
            id: "tue_sat".into(),
            worktime: Some(Worktime {
                days: Some([false, false, true, true, true, true, true]),
                ..Default::default()
            }),
        }],
        resources: vec![
            ResourceData { id: "office".into(), capacity: None, calendar_id: None },
            ResourceData { id: "shop".into(), capacity: None, calendar_id: Some("tue_sat".into()) },
        ],
        ..Default::default()
    };

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

    // One week in day buckets, Monday to Sunday.
    let from = DateTime::from_ymd_hm(2026, 8, 10, 0, 0).ok_or("invalid date")?;
    let to = DateTime::from_ymd_hm(2026, 8, 17, 0, 0).ok_or("invalid date")?;
    let profile = project.load_profile(&ProfileQuery::new(from, to).into())?;

    for row in &profile.resources {
        let capacity: Vec<f64> = row.buckets.iter().map(|b| b.capacity).collect();
        match row.capacity_mode {
            CapacityMode::Calendar => println!("{}: calendar {capacity:?}", row.resource),
            CapacityMode::Flat => println!("{}: flat {capacity:?}", row.resource),
        }
    }
    Ok(())
}
```

`office` has no calendar and gets `Flat` capacity 1.0 every day. `shop` gets `Calendar`, with capacity 0 on Monday and Sunday.

For how capacity and load compare in a profile, see [Resource load](<https://docs.dhtmlx.com/planning-engine/rust/resources-and-assignment/resource-load.md#capacity-modes>).

## Related

- [`ResourceLoad`](<https://docs.dhtmlx.com/planning-engine/rust/api/core/resources/resource-load.md>) - carries the mode for each resource in a profile
- [`CalendarMode`](<https://docs.dhtmlx.com/planning-engine/rust/api/core/data/calendar-mode.md>) - the config setting that selects `Calendar` capacity
- [`ResourceData`](<https://docs.dhtmlx.com/planning-engine/rust/api/core/data/resource-data.md#capacity>) - supplies the capacity value the mode spreads over buckets
- [Resource Load](<https://docs.dhtmlx.com/planning-engine/rust/resources-and-assignment/resource-load.md#capacity-modes>) - compares both modes on one project
