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" 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