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 and ProfileQuery::basis, and LoadProfile::basis reports the basis a profile was built with.

Declaration#

#[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#

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#

pub fn for_unit(unit: TimeUnit) -> Basis

Returns the derived basis for a duration unit.

Parameters

Name Type Description
unit TimeUnit The project's duration unit.

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

Methods#

as_str#

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

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

Example#

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));
}