Skip to content

Commit

Permalink
feat: add From<u8> impl for GameMode
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxOhn committed Oct 27, 2023
1 parent 7949e2f commit 457934f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/target
Cargo.lock
output*
/.idea
/tests/custom.rs

/pp-gen/.env
Expand Down
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## Upcoming

Nothing as of now
- __Additions:__
- Added `From<u8>` impl for `GameMode`

# v0.9.5 (2023-09-06)

Expand Down
17 changes: 12 additions & 5 deletions src/beatmap/mode.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/// The mode of a beatmap.
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)]
#[derive(Copy, Clone, Debug, Default, Hash, PartialEq, Eq)]
pub enum GameMode {
/// osu!standard
#[default]
Osu = 0,
/// osu!taiko
Taiko = 1,
Expand All @@ -11,9 +12,15 @@ pub enum GameMode {
Mania = 3,
}

impl Default for GameMode {
impl From<u8> for GameMode {
#[inline]
fn default() -> Self {
Self::Osu
fn from(mode: u8) -> Self {
match mode {
0 => Self::Osu,
1 => Self::Taiko,
2 => Self::Catch,
3 => Self::Mania,
_ => Self::Osu,
}
}
}
}

0 comments on commit 457934f

Please sign in to comment.