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


# Basis

The size of the time buckets in which resource load is measured and compared with capacity: one hour or one day. It's the type of [`LevelingOptions::basis`](<https://docs.dhtmlx.com/planning-engine/rust/api/core/resources/leveling-options.md#basis>) and [`ProfileQuery::basis`](<https://docs.dhtmlx.com/planning-engine/rust/api/core/resources/profile-query.md>), and [`LoadProfile::basis`](<https://docs.dhtmlx.com/planning-engine/rust/api/core/resources/load-profile.md>) reports the basis a profile was built with.

## Declaration

```rust
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Basis {
    Hour,
    Day,
}
```

With the `serde` feature, `Basis` implements `Serialize` and `Deserialize`, using the lowercase names `"hour"` and `"day"`.

## Variants

| Variant | Description |
|---|---|
| `Hour` | Load is measured per hour bucket. |
| `Day` | Load is measured per day bucket. |

Minute, week and month buckets aren't supported.

## Associated functions

### parse

```rust
pub fn parse(s: &str) -> Option<Basis>
```

Converts a lowercase basis name to a `Basis`.

**Parameters**

| Name | Type | Description |
|---|---|---|
| `s` | `&str` | `"hour"` or `"day"`. Matching is case-sensitive. |

**Returns** - `Some` with the matching variant, or `None` for any other string.

### for_unit

```rust
pub fn for_unit(unit: TimeUnit) -> Basis
```

Returns the derived basis for a duration unit.

**Parameters**

| Name | Type | Description |
|---|---|---|
| `unit` | [`TimeUnit`](<https://docs.dhtmlx.com/planning-engine/rust/api/core/data/time-unit.md>) | The project's duration unit. |

**Returns** - `Basis::Day` for `TimeUnit::Day`; `Basis::Hour` for `TimeUnit::Hour` and `TimeUnit::Minute`.

## Methods

### as_str

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

Returns the lowercase name of the basis: `"hour"` or `"day"`. `Basis::parse` accepts this name back.

## Example

```rust
use plen_core::{Basis, LevelingOptions, TimeUnit};

fn main() {
    assert_eq!(Basis::parse("day"), Some(Basis::Day));
    assert_eq!(Basis::parse("week"), None);
    assert_eq!(Basis::Hour.as_str(), "hour");
    assert_eq!(Basis::for_unit(TimeUnit::Minute), Basis::Hour);

    let options = LevelingOptions {
        basis: Some(Basis::Day),
        ..Default::default()
    };
    assert_eq!(options.basis, Some(Basis::Day));
}
```

## Related

- [`LevelingOptions`](<https://docs.dhtmlx.com/planning-engine/rust/api/core/resources/leveling-options.md>) - sets the bucket size leveling compares load in
- [`ProfileQuery`](<https://docs.dhtmlx.com/planning-engine/rust/api/core/resources/profile-query.md>) - sets the bucket size of a load profile
- [`TimeUnit`](<https://docs.dhtmlx.com/planning-engine/rust/api/core/data/time-unit.md>) - the duration unit the default basis is derived from
- [Leveling Resources](<https://docs.dhtmlx.com/planning-engine/rust/resources-and-assignment/leveling-resources.md>) - how the basis affects which overloads leveling resolves
- [Resource Load](<https://docs.dhtmlx.com/planning-engine/rust/resources-and-assignment/resource-load.md>) - reading load profiles per hour or per day
