Enum tune::scala::SclBuildError[][src]

pub enum SclBuildError {
    ScaleIsTrivial,
    ItemOutOfRange,
    ScaleTooLarge,
}
Expand description

Error reported when building an Scl fails.

Variants

ScaleIsTrivial

The scale does not contain any items except for the default ratio (0 cents).

Examples

let empty_scale = Scl::builder().build();
assert_eq!(empty_scale.unwrap_err(), SclBuildError::ScaleIsTrivial);

let zero_entries_scale = Scl::builder().push_cents(0.0).push_cents(0.0).build();
assert_eq!(
    zero_entries_scale.unwrap_err(),
    SclBuildError::ScaleIsTrivial
);
ItemOutOfRange

The scale contains an item that is smaller than the default ratio (0 cents) or larger than the period.

let item_greater_than_period = Scl::builder()
    .push_cents(50.0)
    .push_cents(100.0)
    .push_cents(200.0) // out of range
    .push_cents(150.0) // period
    .build();
assert_eq!(
    item_greater_than_period.unwrap_err(),
    SclBuildError::ItemOutOfRange
);

let item_smaller_than_zero = Scl::builder()
    .push_cents(-100.0) // out of range
    .push_cents(50.0)
    .push_cents(150.0)
    .push_cents(200.0)  // period
    .build();
assert_eq!(
    item_smaller_than_zero.unwrap_err(),
    SclBuildError::ItemOutOfRange
);

let item_greater_than_zero_period = Scl::builder()
    .push_cents(50.0) // ouf of range
    .push_cents(0.0)  // period
    .build();
assert_eq!(
    item_greater_than_zero_period.unwrap_err(),
    SclBuildError::ItemOutOfRange
);
ScaleTooLarge

There are too many items in this scale.

// The number of items is below the threshold.
let mut below = Scl::builder();
for i in 0..65535 {
    below = below.push_cents(f64::from(i));
}
assert!(below.build().is_ok());

// The number of items is above the threshold.
let mut above = Scl::builder();
for i in 0..65536 {
    above = above.push_cents(f64::from(i));
}
assert_eq!(above.build().unwrap_err(), SclBuildError::ScaleTooLarge);

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Performs the conversion.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.