Add module src/free_api_v25/current/weather.rs

This commit is contained in:
Candifloss 2025-10-10 00:38:17 +05:30
parent c45bbaa0f1
commit ee7820eb64
2 changed files with 52 additions and 0 deletions

View File

@ -18,3 +18,4 @@
//! - [`query`](crate::query) for building request URLs
pub mod coord;
pub mod weather;

View File

@ -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)
}
}