- Move OWM library crate to a seperate repo - https://git.candifloss.cc/candifloss/OpenWeatherMapSDK.git
46 lines
1.1 KiB
Rust
46 lines
1.1 KiB
Rust
use owm_rs::free_api_v25::query::{QueryParams, Units};
|
|
use serde::Deserialize;
|
|
|
|
#[derive(Debug, Deserialize)]
|
|
pub struct Free25Query {
|
|
pub api_key: String,
|
|
pub city_id: Option<String>,
|
|
pub city_name: Option<String>,
|
|
pub lat: Option<f32>,
|
|
pub lon: Option<f32>,
|
|
pub zip: Option<String>,
|
|
#[serde(default = "default_units")]
|
|
pub units: String, // "metric", "imperial", "standard"
|
|
#[serde(default = "default_lang")]
|
|
pub lang: String, // default "en"
|
|
}
|
|
|
|
fn default_units() -> String {
|
|
"standard".into()
|
|
}
|
|
|
|
fn default_lang() -> String {
|
|
"en".into()
|
|
}
|
|
|
|
impl From<Free25Query> for QueryParams {
|
|
fn from(cfg: Free25Query) -> Self {
|
|
let units = match cfg.units.as_str() {
|
|
"metric" => Units::Metric,
|
|
"imperial" => Units::Imperial,
|
|
_ => Units::Standard,
|
|
};
|
|
|
|
QueryParams {
|
|
api_key: cfg.api_key,
|
|
city_id: cfg.city_id,
|
|
city_name: cfg.city_name,
|
|
lat: cfg.lat,
|
|
lon: cfg.lon,
|
|
zip: cfg.zip,
|
|
units,
|
|
lang: cfg.lang,
|
|
}
|
|
}
|
|
}
|