/
qwars
/
weather-cli
Обзор
Документация
Войти
/
qwars
/
weather-cli
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
src/types.rs
126 строк
3 KB
Alexandr Selunin
Основное для показа погоды
24 окт 2025, 02:41
24 окт 2025, 02:41
253aacb
Код
Авторство
О чём код?
// types.rs use clap::Parser; use serde::Deserialize; #[derive(Parser, Debug, Clone)] #[command(author, version, about)] pub struct Args { #[arg(short, long, help = "Название города (например: Moscow, Екатеринбург)")] pub city: Option<String>, #[arg( long, help = "Координаты в формате 'широта,долгота' (например: 56.850,60.600)" )] pub coords: Option<String>, } #[derive(Deserialize)] pub struct WeatherDesc { pub value: String, } #[derive(Deserialize)] pub struct AreaName { pub value: String, } #[derive(Deserialize)] pub struct CurrentCondition { #[serde(rename = "temp_C")] pub temp_c: String, #[serde(rename = "weatherCode")] pub weather_code: String, #[serde(rename = "weatherDesc")] pub weather_desc: Vec<WeatherDesc>, } #[derive(Deserialize)] pub struct NearestArea { #[serde(rename = "areaName")] pub area_name: Vec<AreaName>, } #[derive(Deserialize)] pub struct WeatherResponse { #[serde(rename = "current_condition")] pub current_condition: Vec<CurrentCondition>, #[serde(rename = "nearest_area")] pub nearest_area: Vec<NearestArea>, } #[derive(Clone, Copy)] pub struct ColoredChar { pub ch: char, pub fg: Option<u8>, pub bg: Option<u8>, pub invert: bool, } #[macro_export] macro_rules! cc { ($ch:expr) => { ColoredChar { ch: $ch, fg: None, bg: None, invert: false, } }; (fg=$fg:expr, $ch:expr) => { ColoredChar { ch: $ch, fg: Some($fg), bg: None, invert: false, } }; (bg=$bg:expr, $ch:expr) => { ColoredChar { ch: $ch, bg: Some($bg), fg: None, invert: false, } }; (fg=$fg:expr, bg=$bg:expr, $ch:expr) => { ColoredChar { ch: $ch, fg: Some($fg), bg: Some($bg), invert: false, } }; (inv, $ch:expr) => { ColoredChar { ch: $ch, fg: None, bg: None, invert: true, } }; (fg=$fg:expr, inv, $ch:expr) => { ColoredChar { ch: $ch, fg: Some($fg), bg: None, invert: true, } }; (fg=$fg:expr, bg=$bg:expr, inv, $ch:expr) => { ColoredChar { ch: $ch, fg: Some($fg), bg: Some($bg), invert: true, } }; (bg=$bg:expr, inv, $ch:expr) => { ColoredChar { ch: $ch, bg: Some($bg), fg: None, invert: true, } }; }