Add module src/free_api_v25/current/main.rs
This commit is contained in:
parent
e9aa4cbd13
commit
d715302a8f
58
src/free_api_v25/current/main.rs
Normal file
58
src/free_api_v25/current/main.rs
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
/// Main weather parameters including temperature, pressure, and humidity
|
||||||
|
///
|
||||||
|
/// All temperature values are in the units specified in the API request
|
||||||
|
/// (Kelvin, Celsius, or Fahrenheit).
|
||||||
|
#[derive(Debug, Clone, Deserialize, Serialize, Default, PartialEq)]
|
||||||
|
pub struct Main {
|
||||||
|
/// Temperature in requested units (Kelvin, Celsius, or Fahrenheit)
|
||||||
|
#[serde(default)]
|
||||||
|
pub temp: Option<f32>,
|
||||||
|
/// "Feels like" temperature, accounting for human perception of weather
|
||||||
|
#[serde(default)]
|
||||||
|
pub feels_like: Option<f32>,
|
||||||
|
/// Minimum observed temperature (within large urban areas)
|
||||||
|
#[serde(default)]
|
||||||
|
pub temp_min: Option<f32>,
|
||||||
|
/// Maximum observed temperature (within large urban areas)
|
||||||
|
#[serde(default)]
|
||||||
|
pub temp_max: Option<f32>,
|
||||||
|
/// Atmospheric pressure at sea level (hPa)
|
||||||
|
#[serde(default)]
|
||||||
|
pub pressure: Option<u32>,
|
||||||
|
/// Humidity percentage (0-100)
|
||||||
|
#[serde(default)]
|
||||||
|
pub humidity: Option<u8>,
|
||||||
|
/// Atmospheric pressure at sea level (hPa)
|
||||||
|
#[serde(default)]
|
||||||
|
pub sea_level: Option<u32>,
|
||||||
|
/// Atmospheric pressure at ground level (hPa)
|
||||||
|
#[serde(default)]
|
||||||
|
pub grnd_level: Option<u32>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Main {
|
||||||
|
/// Returns the temperature difference between max and min
|
||||||
|
///
|
||||||
|
/// # Example
|
||||||
|
/// ```
|
||||||
|
/// use owm_api25::current::Main;
|
||||||
|
///
|
||||||
|
/// let main = Main {
|
||||||
|
/// temp: Some(20.0),
|
||||||
|
/// temp_min: Some(15.0),
|
||||||
|
/// temp_max: Some(25.0),
|
||||||
|
/// ..Default::default()
|
||||||
|
/// };
|
||||||
|
///
|
||||||
|
/// assert_eq!(main.temp_range(), Some(10.0));
|
||||||
|
/// ```
|
||||||
|
#[must_use]
|
||||||
|
pub fn temp_range(&self) -> Option<f32> {
|
||||||
|
match (self.temp_min, self.temp_max) {
|
||||||
|
(Some(min), Some(max)) => Some(max - min),
|
||||||
|
_ => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -18,4 +18,5 @@
|
|||||||
//! - [`query`](crate::query) for building request URLs
|
//! - [`query`](crate::query) for building request URLs
|
||||||
|
|
||||||
pub mod coord;
|
pub mod coord;
|
||||||
|
pub mod main;
|
||||||
pub mod weather;
|
pub mod weather;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user