Update library
- More complete
This commit is contained in:
parent
a2bdf239e0
commit
6959ec1e67
@ -8,3 +8,4 @@ toml = "0.9.6"
|
|||||||
dirs = "6.0.0"
|
dirs = "6.0.0"
|
||||||
serde = { version = "1.0.225", features = ["derive"] }
|
serde = { version = "1.0.225", features = ["derive"] }
|
||||||
serde_json = "1.0.145"
|
serde_json = "1.0.145"
|
||||||
|
chrono = "0.4.42"
|
||||||
|
@ -1,30 +1,97 @@
|
|||||||
|
use chrono::{DateTime, Utc};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
use std::collections::HashMap;
|
||||||
|
|
||||||
|
#[derive(Debug, Deserialize, Serialize)]
|
||||||
|
pub struct Coord {
|
||||||
|
pub lon: f64,
|
||||||
|
pub lat: f64,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, Serialize)]
|
#[derive(Debug, Deserialize, Serialize)]
|
||||||
pub struct Weather {
|
pub struct Weather {
|
||||||
|
pub id: u32,
|
||||||
pub main: String,
|
pub main: String,
|
||||||
pub icon: String,
|
|
||||||
pub description: String,
|
pub description: String,
|
||||||
|
pub icon: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, Serialize)]
|
#[derive(Debug, Deserialize, Serialize)]
|
||||||
pub struct Main {
|
pub struct Main {
|
||||||
pub temp: f32,
|
pub temp: f32,
|
||||||
pub pressure: u32,
|
pub feels_like: Option<f32>,
|
||||||
pub humidity: u8,
|
pub temp_min: Option<f32>,
|
||||||
|
pub temp_max: Option<f32>,
|
||||||
|
pub pressure: Option<u32>,
|
||||||
|
pub humidity: Option<u8>,
|
||||||
|
pub sea_level: Option<u32>,
|
||||||
|
pub grnd_level: Option<u32>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Deserialize, Serialize)]
|
||||||
|
pub struct Wind {
|
||||||
|
pub speed: Option<f32>,
|
||||||
|
pub deg: Option<u16>,
|
||||||
|
pub gust: Option<f32>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Deserialize, Serialize, Default)]
|
||||||
|
pub struct Clouds {
|
||||||
|
pub all: Option<u8>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Deserialize, Serialize)]
|
||||||
|
pub struct Precipitation {
|
||||||
|
#[serde(rename = "1h")]
|
||||||
|
pub one_hour: Option<f32>,
|
||||||
|
#[serde(rename = "3h")]
|
||||||
|
pub three_hour: Option<f32>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, Serialize)]
|
#[derive(Debug, Deserialize, Serialize)]
|
||||||
pub struct Sys {
|
pub struct Sys {
|
||||||
pub country: String,
|
pub r#type: Option<u8>,
|
||||||
pub sunrise: u64,
|
pub id: Option<u32>,
|
||||||
pub sunset: u64,
|
pub country: Option<String>,
|
||||||
|
pub sunrise: Option<u64>,
|
||||||
|
pub sunset: Option<u64>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, Serialize)]
|
#[derive(Debug, Deserialize, Serialize)]
|
||||||
pub struct WeatherResponse {
|
pub struct WeatherResponse {
|
||||||
pub name: String,
|
pub coord: Option<Coord>,
|
||||||
pub sys: Sys,
|
#[serde(default)]
|
||||||
pub weather: Vec<Weather>,
|
pub weather: Vec<Weather>,
|
||||||
|
pub base: Option<String>,
|
||||||
pub main: Main,
|
pub main: Main,
|
||||||
|
pub visibility: Option<u32>,
|
||||||
|
pub wind: Option<Wind>,
|
||||||
|
pub clouds: Option<Clouds>,
|
||||||
|
|
||||||
|
/// Optional precipitation data
|
||||||
|
/// "rain": { "1h": f32 } or "3h": f32
|
||||||
|
#[serde(default)]
|
||||||
|
pub rain: Option<Precipitation>,
|
||||||
|
|
||||||
|
/// "snow": { "1h": f32 } or "3h": f32
|
||||||
|
#[serde(default)]
|
||||||
|
pub snow: Option<Precipitation>,
|
||||||
|
|
||||||
|
#[serde(with = "chrono::serde::ts_seconds_option")]
|
||||||
|
pub dt: Option<DateTime<Utc>>,
|
||||||
|
pub sys: Sys,
|
||||||
|
pub timezone: Option<i32>,
|
||||||
|
pub id: Option<u64>,
|
||||||
|
pub name: String,
|
||||||
|
pub cod: Option<u16>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl WeatherResponse {
|
||||||
|
pub fn primary_weather(&self) -> Option<&Weather> {
|
||||||
|
self.weather.first()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn is_success(&self) -> bool {
|
||||||
|
self.cod.map_or(true, |code| code == 200)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user