From ee7820eb64be0743f2f564b1d90ed8bb21c5753a Mon Sep 17 00:00:00 2001 From: Candifloss Date: Fri, 10 Oct 2025 00:38:17 +0530 Subject: [PATCH] Add module `src/free_api_v25/current/weather.rs` --- src/free_api_v25/current/mod.rs | 1 + src/free_api_v25/current/weather.rs | 51 +++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 src/free_api_v25/current/weather.rs diff --git a/src/free_api_v25/current/mod.rs b/src/free_api_v25/current/mod.rs index 0595e57..b4cf5f4 100644 --- a/src/free_api_v25/current/mod.rs +++ b/src/free_api_v25/current/mod.rs @@ -18,3 +18,4 @@ //! - [`query`](crate::query) for building request URLs pub mod coord; +pub mod weather; diff --git a/src/free_api_v25/current/weather.rs b/src/free_api_v25/current/weather.rs new file mode 100644 index 0000000..9c37cb1 --- /dev/null +++ b/src/free_api_v25/current/weather.rs @@ -0,0 +1,51 @@ +/// Weather condition information +/// +/// Contains details about current weather conditions including +/// human-readable descriptions and icon identifiers. +/// +/// See: [Weather condition codes](https://openweathermap.org/weather-conditions) +#[derive(Debug, Clone, Deserialize, Serialize, Default, PartialEq)] +pub struct Weather { + /// Weather condition ID + /// + /// See: [Weather condition codes](https://openweathermap.org/weather-conditions) + pub id: u32, + + /// Group of weather parameters (e.g. Rain, Snow, Clouds) + pub main: String, + + /// Human-readable weather condition description + /// + /// This field can be localized based on the API request. + pub description: String, + + /// Weather icon ID (for retrieving icon assets) + /// + /// Combine with base URL: `https://openweathermap.org/img/wn/{icon}@2x.png` + pub icon: String, +} + +impl Weather { + /// Returns the URL to the weather icon image + /// + /// # Example + /// ``` + /// use owm_api25::current::Weather; + /// + /// let weather = Weather { + /// id: 501, + /// main: "Rain".to_string(), + /// description: "moderate rain".to_string(), + /// icon: "10d".to_string(), + /// }; + /// + /// assert_eq!( + /// weather.icon_url(), + /// "https://openweathermap.org/img/wn/10d@2x.png" + /// ); + /// ``` + #[must_use] + pub fn icon_url(&self) -> String { + format!("https://openweathermap.org/img/wn/{}@2x.png", self.icon) + } +} \ No newline at end of file