use serde::{Deserialize, Serialize}; /// 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) } }