Skip to content

Commit

Permalink
Removed some panics by using default values
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxOhn committed Jun 16, 2020
1 parent 43a6e98 commit c3e3eb1
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rosu"
version = "0.2.1"
version = "0.2.2"
authors = ["MaxOhn <ohn.m@hotmail.de>"]
edition = "2018"
description = "A wrapper for the osu! API."
Expand Down
2 changes: 1 addition & 1 deletion src/backend/deserialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ pub(crate) fn str_to_mods<'de, D>(d: D) -> Result<GameMods, D::Error>
where
D: Deserializer<'de>,
{
Ok(str_to_maybe_mods(d)?.unwrap())
Ok(str_to_maybe_mods(d)?.unwrap_or_else(GameMods::default))
}

pub(crate) fn str_to_grade<'de, D>(d: D) -> Result<Grade, D::Error>
Expand Down
11 changes: 3 additions & 8 deletions src/models/match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,10 @@ pub enum ScoringType {
impl From<u8> for ScoringType {
fn from(t: u8) -> Self {
match t {
0 => Self::Score,
1 => Self::Accuracy,
2 => Self::Combo,
3 => Self::ScoreV2,
_ => {
panic!("Can not parse {} into ScoringType", t);
}
_ => Self::Score,
}
}
}
Expand All @@ -156,11 +153,10 @@ pub enum TeamType {
impl From<u8> for TeamType {
fn from(t: u8) -> Self {
match t {
0 => Self::HeadToHead,
1 => Self::TagCoop,
2 => Self::TeamVS,
3 => Self::TagTeamVS,
_ => panic!("Can not parse {} into TeamType", t),
_ => Self::HeadToHead,
}
}
}
Expand All @@ -177,10 +173,9 @@ pub enum Team {
impl From<u8> for Team {
fn from(t: u8) -> Self {
match t {
0 => Self::None,
1 => Self::Blue,
2 => Self::Red,
_ => panic!("Can not parse {} into Team", t),
_ => Self::None,
}
}
}
3 changes: 1 addition & 2 deletions src/models/mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,10 @@ impl fmt::Display for GameMode {
impl From<u8> for GameMode {
fn from(m: u8) -> Self {
match m {
0 => Self::STD,
1 => Self::TKO,
2 => Self::CTB,
3 => Self::MNA,
_ => panic!("Can not parse {} into GameMode", m),
_ => Self::STD,
}
}
}

0 comments on commit c3e3eb1

Please sign in to comment.