diff --git a/src/models/price.rs b/src/models/price.rs index 8cf22ff..a415b52 100644 --- a/src/models/price.rs +++ b/src/models/price.rs @@ -27,26 +27,16 @@ pub struct StationPrices { /// Station open or closed pub status: String, /// Price for E5 - #[serde(deserialize_with = "de_from_bool_or_number", default = "default_fuel")] + #[serde(deserialize_with = "de_from_bool_or_number", default)] pub e5: Option, /// Price for E10 - #[serde(deserialize_with = "de_from_bool_or_number", default = "default_fuel")] + #[serde(deserialize_with = "de_from_bool_or_number", default)] pub e10: Option, /// Price for diesel - #[serde(deserialize_with = "de_from_bool_or_number", default = "default_fuel")] + #[serde(deserialize_with = "de_from_bool_or_number", default)] pub diesel: Option, } -/// This function should just return always null as fallback. -/// This is required as the custom deserialization can't handle missing values. -fn default_fuel() -> Option { - if 1 < 0 { - Some(1_f64) - } else { - None - } -} - fn de_from_bool_or_number<'de, D>(deserializer: D) -> Result, D::Error> where D: Deserializer<'de>, @@ -200,5 +190,37 @@ mod test { .diesel, None ); + assert_eq!( + prices_response + .prices + .get("55555555-4444-4444-4444-444444444444") + .unwrap() + .status, + "no prices" + ); + assert_eq!( + prices_response + .prices + .get("55555555-4444-4444-4444-444444444444") + .unwrap() + .e5, + None + ); + assert_eq!( + prices_response + .prices + .get("55555555-4444-4444-4444-444444444444") + .unwrap() + .e10, + None + ); + assert_eq!( + prices_response + .prices + .get("55555555-4444-4444-4444-444444444444") + .unwrap() + .diesel, + None + ); } } diff --git a/test/data/prices.json b/test/data/prices.json index 86178bc..482c95f 100644 --- a/test/data/prices.json +++ b/test/data/prices.json @@ -20,6 +20,12 @@ }, "44444444-4444-4444-4444-444444444444": { "status": "no prices" + }, + "55555555-4444-4444-4444-444444444444": { + "status": "no prices", + "e5": null, + "e10": null, + "diesel": null } } }