openmeteo-rs 1.0.0

Rust client for the Open-Meteo weather API.
Documentation
//! Request-side unit and location-selection types.

use std::borrow::Cow;

use crate::query::AsApiStr;

/// Temperature unit requested from the API.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, serde::Serialize)]
#[non_exhaustive]
pub enum TemperatureUnit {
    /// Celsius.
    Celsius,
    /// Fahrenheit.
    Fahrenheit,
}

impl AsApiStr for TemperatureUnit {
    fn as_api_str(&self) -> Cow<'static, str> {
        Cow::Borrowed(match self {
            Self::Celsius => "celsius",
            Self::Fahrenheit => "fahrenheit",
        })
    }
}

/// Wind-speed unit requested from the API.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, serde::Serialize)]
#[non_exhaustive]
pub enum WindSpeedUnit {
    /// Kilometres per hour.
    Kmh,
    /// Metres per second.
    Ms,
    /// Miles per hour.
    Mph,
    /// Knots.
    Kn,
}

impl AsApiStr for WindSpeedUnit {
    fn as_api_str(&self) -> Cow<'static, str> {
        Cow::Borrowed(match self {
            Self::Kmh => "kmh",
            Self::Ms => "ms",
            Self::Mph => "mph",
            Self::Kn => "kn",
        })
    }
}

/// Length unit requested from marine APIs.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, serde::Serialize)]
#[non_exhaustive]
pub enum LengthUnit {
    /// Metric units.
    Metric,
    /// Imperial units.
    Imperial,
}

impl AsApiStr for LengthUnit {
    fn as_api_str(&self) -> Cow<'static, str> {
        Cow::Borrowed(match self {
            Self::Metric => "metric",
            Self::Imperial => "imperial",
        })
    }
}

/// Precipitation unit requested from the API.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, serde::Serialize)]
#[non_exhaustive]
pub enum PrecipitationUnit {
    /// Millimetres.
    Mm,
    /// Inches.
    Inch,
}

impl AsApiStr for PrecipitationUnit {
    fn as_api_str(&self) -> Cow<'static, str> {
        Cow::Borrowed(match self {
            Self::Mm => "mm",
            Self::Inch => "inch",
        })
    }
}

/// Timestamp format requested from the API.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, serde::Serialize)]
#[non_exhaustive]
pub enum TimeFormat {
    /// ISO-8601 local timestamps.
    Iso8601,
    /// Unix timestamps.
    UnixTime,
}

impl AsApiStr for TimeFormat {
    fn as_api_str(&self) -> Cow<'static, str> {
        Cow::Borrowed(match self {
            Self::Iso8601 => "iso8601",
            Self::UnixTime => "unixtime",
        })
    }
}

/// Timezone requested from the API.
#[derive(Debug, Clone, PartialEq, Eq, Hash, serde::Serialize)]
#[non_exhaustive]
pub enum Timezone {
    /// Let Open-Meteo resolve the timezone from the coordinate.
    Auto,
    /// Greenwich Mean Time.
    Gmt,
    /// IANA timezone name, for example `Europe/Zurich`.
    Iana(String),
}

impl AsApiStr for Timezone {
    fn as_api_str(&self) -> Cow<'static, str> {
        match self {
            Self::Auto => Cow::Borrowed("auto"),
            Self::Gmt => Cow::Borrowed("GMT"),
            Self::Iana(value) => Cow::Owned(value.clone()),
        }
    }
}

/// Grid-cell selection strategy near coastlines.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, serde::Serialize)]
#[non_exhaustive]
pub enum CellSelection {
    /// Prefer land cells.
    Land,
    /// Prefer sea cells.
    Sea,
    /// Use the nearest cell.
    Nearest,
}

impl AsApiStr for CellSelection {
    fn as_api_str(&self) -> Cow<'static, str> {
        Cow::Borrowed(match self {
            Self::Land => "land",
            Self::Sea => "sea",
            Self::Nearest => "nearest",
        })
    }
}