From 71aec0b7b14fbcf0440d63e1bc04a855daf18741 Mon Sep 17 00:00:00 2001 From: Alex Ford Date: Sat, 17 Aug 2019 03:37:56 -0600 Subject: [PATCH 1/2] Expose serde errors, and account for certain fields not existing --- src/lib.rs | 6 +++--- src/weather_types.rs | 4 +++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 882dc67..12fc7ec 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -74,8 +74,8 @@ fn get(url: &str) -> Result where T: serde::de::DeserializeOw Err(_) => { let err_report: ErrorReport = match serde_json::from_str(res.as_str()) { Ok(report) => {report}, - Err(_) => { - return Err(ErrorReport{cod: 0, message: format!("Got unexpected response: {:?}", res)}); + Err(serde_error) => { + return Err(ErrorReport{cod: 0, message: format!("Parsing error {}\n\nResponse: {}", serde_error, res)}); } }; return Err(err_report); @@ -202,4 +202,4 @@ pub fn get_historical_uv_index(location: LocationSpecifier, key: &str, start: ti let url = Url::parse_with_params(&base, params).unwrap(); get(&url.as_str()) -} \ No newline at end of file +} diff --git a/src/weather_types.rs b/src/weather_types.rs index 5eba86e..7ee75a0 100644 --- a/src/weather_types.rs +++ b/src/weather_types.rs @@ -6,6 +6,7 @@ pub struct Coordinates { #[derive(Serialize, Deserialize, Debug)] pub struct CityShort { + #[serde(default)] pub id: u32, pub name: String, pub coord: Coordinates, @@ -57,7 +58,7 @@ pub struct Wind { pub gust: Option, } -#[derive(Serialize, Deserialize, Debug)] +#[derive(Default,Serialize, Deserialize, Debug)] pub struct Rain { #[serde(rename="3h")] pub three_h: Option, @@ -85,6 +86,7 @@ pub struct TimeSliceHourly { pub weather: Vec, pub clouds: Clouds, pub wind: Wind, + #[serde(default)] pub rain: Rain, pub sys: System, pub dt_txt: String From 2bb6da02fdceb117787fd48b561b0fa141bcc239 Mon Sep 17 00:00:00 2001 From: Alex Ford Date: Tue, 15 Oct 2019 02:20:26 -0600 Subject: [PATCH 2/2] Bump reqwest version to avoid openssl compile failures --- Cargo.toml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index af7b038..7775063 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "openweather" -version = "0.0.1" +version = "0.0.2" authors = ["Broderick Carlin "] description = "A rust crate wrapping openweather's API into a simple easy to use interface" repository = "https://github.com/BroderickCarlin/openweather" @@ -15,9 +15,9 @@ name = "openweather" path = "src/lib.rs" [dependencies] -reqwest = "0.8.6" +reqwest = "0.9" serde_json = "1.0" serde = "1.0.70" serde_derive = "1.0.70" time = "0.1.40" -url = "1.5.1" \ No newline at end of file +url = "1.5.1"