Skip to content

Commit

Permalink
Playtime: Fix panic when converting BPM values
Browse files Browse the repository at this point in the history
  • Loading branch information
helgoboss committed Feb 20, 2024
1 parent cbd2ac1 commit 1cc375d
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions playtime-api/src/persistence/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1483,14 +1483,14 @@ pub struct Bpm(f64);
impl Bpm {
/// # Safety
///
/// If you pass a value <= 0.0, you get an invalid Bpm value.
/// If you pass a value < 1.0 or > 960.0, you get an invalid Bpm value.
pub const unsafe fn new_unchecked(value: f64) -> Self {
Self(value)
}

pub fn new(value: f64) -> PlaytimeApiResult<Self> {
if value <= 0.0 {
return Err("BPM value must be > 0.0".into());
if value < 1.0 || value > 960.0 {
return Err("BPM value must be >= 1.0 and <= 960.0".into());
}
Ok(Self(value))
}
Expand Down

0 comments on commit 1cc375d

Please sign in to comment.