From 62df1856911d5655725c80f42e13a46cf765637c Mon Sep 17 00:00:00 2001 From: TotallyNot <44345987+TotallyNot@users.noreply.github.com> Date: Sat, 29 Jul 2023 17:34:42 +0200 Subject: [PATCH] added fallback competition case --- torn-api/src/user.rs | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/torn-api/src/user.rs b/torn-api/src/user.rs index 912baae..7d7094a 100644 --- a/torn-api/src/user.rs +++ b/torn-api/src/user.rs @@ -172,6 +172,7 @@ pub enum Competition { attacks: i16, team: EliminationTeam, }, + Unknown, } fn deserialize_comp<'de, D>(deserializer: D) -> Result, D::Error> @@ -186,11 +187,15 @@ where Team, Attacks, TeamName, + #[serde(other)] + Ignore, } #[derive(Deserialize)] enum CompetitionName { Elimination, + #[serde(other)] + Unknown, } struct CompetitionVisitor; @@ -294,6 +299,7 @@ where Ok(None) } } + CompetitionName::Unknown => Ok(Some(Competition::Unknown)), } } } @@ -357,7 +363,7 @@ pub struct PersonalStats { } #[derive(Deserialize)] -pub struct CriminalRecord { +pub struct Crimes1 { pub selling_illegal_products: i32, pub theft: i32, pub auto_theft: i32, @@ -369,6 +375,29 @@ pub struct CriminalRecord { pub total: i32, } +#[derive(Deserialize)] +pub struct Crimes2 { + pub vandalism: i32, + pub theft: i32, + pub counterfeiting: i32, + pub fraud: i32, + #[serde(rename = "illicitservices")] + pub illicit_services: i32, + #[serde(rename = "cybercrime")] + pub cyber_crime: i32, + pub extortion: i32, + #[serde(rename = "illegalproduction")] + pub illegal_production: i32, + pub total: i32, +} + +#[derive(Deserialize)] +#[serde(untagged)] +pub enum CriminalRecord { + Crimes1(Crimes1), + Crimes2(Crimes2), +} + #[cfg(test)] mod tests { use super::*;