Enum tune::scala::SclBuildError [−][src]
pub enum SclBuildError {
ScaleIsTrivial,
ItemOutOfRange,
ScaleTooLarge,
}
Expand description
Error reported when building an Scl
fails.
Variants
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
);
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
);
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
Performs the conversion.
Auto Trait Implementations
impl RefUnwindSafe for SclBuildError
impl Send for SclBuildError
impl Sync for SclBuildError
impl Unpin for SclBuildError
impl UnwindSafe for SclBuildError
Blanket Implementations
Mutably borrows from an owned value. Read more