Skip to main content

Crate weatherkit

Crate weatherkit 

Source
Expand description

§weatherkit-rs

Safe Rust bindings for Apple’s WeatherKit framework on macOS 13+.

The published package is weatherkit-doomfish; the Rust library crate is imported as weatherkit.

Status: v0.3.0 covers the full non-exempt macOS WeatherKit surface, including WeatherService multi-query helpers, statistics/summaries, weather changes, historical comparisons, enum descriptor catalogs, and an executor-agnostic async API.

§Quick start

use weatherkit::prelude::*;

fn main() -> Result<(), WeatherKitError> {
    let service = WeatherService::shared();
    let location = CLLocation::new(37.3349, -122.0090);
    let current = service.current_weather(&location)?;

    println!(
        "current temperature: {:.1}°C ({:?})",
        current.temperature,
        current.condition
    );
    Ok(())
}

§Async API

Enable with the async Cargo feature to get executor-agnostic Future wrappers for every async throws surface on WeatherService:

use weatherkit::async_api::AsyncWeatherService;
use weatherkit::service::CLLocation;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    pollster::block_on(async {
        let svc = AsyncWeatherService::shared();
        let loc = CLLocation::new(37.3382, -121.8863);
        let weather = svc.weather(&loc).await
            .map_err(|e| Box::new(e) as Box<dyn std::error::Error>)?;
        println!("{:?}", weather.current_weather.condition);
        Ok(())
    })
}

Available futures: WeatherFuture, CurrentWeatherFuture, HourlyForecastFuture, DailyForecastFuture, MinuteForecastFuture, WeatherAlertsFuture, AvailabilityFuture, AttributionFuture, WeatherChangesFuture (macOS 15+), HistoricalComparisonsFuture (macOS 15+).

See examples/17_async_weather.rs and tests/async_api_tests.rs for full usage.

§Highlights

  • WeatherService::weather, current_weather, daily_forecast, hourly_forecast, minute_forecast, weather_alerts, availability, attribution, and multi-query weather_including{2..6} / weather_including_many
  • DailyForecast / HourlyForecast containers with WeatherKit metadata plus DayForecast / HourForecast entries
  • macOS 15+ statistics and summary wrappers (DailyWeatherStatistics, DailyWeatherSummary, HourlyWeatherStatistics, MonthlyWeatherStatistics) with query enums and service helpers
  • WeatherChanges, HistoricalComparisons, Trend, TrendBaseline, and Percentiles for the new WeatherKit comparison/change-tracking APIs
  • CurrentWeather with precipitation intensity, metadata, and cloud-cover-by-altitude when available on macOS 15+
  • DayForecast with SunEvents, MoonEvents, UVIndex, wind, day-part forecasts, and precipitation-by-type details when available
  • Descriptor catalogs for WeatherAttribution, WeatherSeverity, AvailabilityKind, WeatherCondition, Precipitation, PressureTrend, MoonPhase, WindCompassDirection, UVExposureCategory, and WeatherError
  • Async Swift APIs bridged to synchronous Rust via DispatchSemaphore + Task, with opaque handle ownership released on the Rust side

§Entitlements / caveats

WeatherKit usually requires an entitled bundle ID backed by a paid Apple Developer membership. Unsigned CLI binaries often fail with permission or bundle-configuration errors; every example in examples/ treats that as a caveat instead of a hard failure.

§Examples

Each logical area has a dedicated example:

cargo run --example 01_weather_service_smoke
cargo run --example 02_current_weather_snapshot
cargo run --example 03_daily_forecast_snapshot
cargo run --example 04_hourly_forecast_snapshot
cargo run --example 05_weather_alerts_snapshot
cargo run --example 06_minute_forecast_snapshot
cargo run --example 07_availability_kind_catalog
cargo run --example 08_weather_attribution_snapshot
cargo run --example 09_sun_events_snapshot
cargo run --example 10_moon_events_snapshot
cargo run --example 11_weather_condition_catalog
cargo run --example 12_pressure_catalog
cargo run --example 13_weather_changes_snapshot
cargo run --example 14_weather_statistics_snapshot
cargo run --example 15_weather_multi_query_snapshot
cargo run --example 16_weather_enum_catalog

§License

Licensed under either Apache-2.0 or MIT at your option. Safe Rust bindings for WeatherKit.

Re-exports§

pub use availability_kind::AvailabilityKind;
pub use availability_kind::AvailabilityKindDescriptor;
pub use availability_kind::WeatherAvailability;
pub use changes::Deviation;
pub use changes::HistoricalComparison;
pub use changes::HistoricalComparisons;
pub use changes::LengthUnit;
pub use changes::Percentiles;
pub use changes::TemperatureUnit;
pub use changes::Trend;
pub use changes::TrendBaseline;
pub use changes::TrendBaselineKind;
pub use changes::WeatherChange;
pub use changes::WeatherChangeDirection;
pub use changes::WeatherChanges;
pub use current_weather::CloudCoverByAltitude;
pub use current_weather::CurrentWeather;
pub use current_weather::UVExposureCategory;
pub use current_weather::UVExposureCategoryDescriptor;
pub use current_weather::UVIndex;
pub use current_weather::Wind;
pub use current_weather::WindCompassDirection;
pub use current_weather::WindCompassDirectionDescriptor;
pub use daily_forecast::DailyForecast;
pub use daily_forecast::DayForecast;
pub use daily_forecast::DayPartForecast;
pub use daily_forecast::PrecipitationAmountByType;
pub use daily_forecast::SnowfallAmount;
pub use error::WeatherError;
pub use error::WeatherErrorDescriptor;
pub use error::WeatherKitError;
pub use error::WEATHERKIT_BRIDGE_ERROR_DOMAIN;
pub use hourly_forecast::HourForecast;
pub use hourly_forecast::HourlyForecast;
pub use minute_forecast::MinuteForecast;
pub use minute_forecast::MinuteForecastCollection;
pub use moon_events::MoonEvents;
pub use moon_events::MoonPhase;
pub use moon_events::MoonPhaseDescriptor;
pub use pressure::Pressure;
pub use pressure::PressureTrend;
pub use pressure::PressureTrendDescriptor;
pub use service::CLLocation;
pub use service::DateInterval;
pub use service::Weather;
pub use service::WeatherMetadata;
pub use service::WeatherQuery;
pub use service::WeatherQueryResult;
pub use service::WeatherService;
pub use statistics::DailyWeatherStatistics;
pub use statistics::DailyWeatherStatisticsQuery;
pub use statistics::DailyWeatherStatisticsResult;
pub use statistics::DailyWeatherSummary;
pub use statistics::DailyWeatherSummaryQuery;
pub use statistics::DailyWeatherSummaryResult;
pub use statistics::DayPrecipitationStatistics;
pub use statistics::DayPrecipitationSummary;
pub use statistics::DayTemperatureStatistics;
pub use statistics::DayTemperatureSummary;
pub use statistics::HourTemperatureStatistics;
pub use statistics::HourlyWeatherStatistics;
pub use statistics::HourlyWeatherStatisticsQuery;
pub use statistics::MonthPrecipitationStatistics;
pub use statistics::MonthTemperatureStatistics;
pub use statistics::MonthlyWeatherStatistics;
pub use statistics::MonthlyWeatherStatisticsQuery;
pub use statistics::MonthlyWeatherStatisticsResult;
pub use sun_events::SunEvents;
pub use weather_alert::WeatherAlert;
pub use weather_alert::WeatherSeverity;
pub use weather_alert::WeatherSeverityDescriptor;
pub use weather_attribution::WeatherAttribution;
pub use weather_condition::Precipitation;
pub use weather_condition::PrecipitationDescriptor;
pub use weather_condition::WeatherCondition;
pub use weather_condition::WeatherConditionDescriptor;

Modules§

async_apiasync
Async API for WeatherKit — executor-agnostic Future wrappers.
availability_kind
WeatherKit availability types.
changes
WeatherKit change-tracking and historical comparison types.
current_weather
WeatherKit current weather types.
daily_forecast
WeatherKit daily forecast types.
error
WeatherKit error types.
ffi
Low-level WeatherKit bridge bindings.
hourly_forecast
WeatherKit hourly forecast types.
minute_forecast
WeatherKit minute forecast types.
moon_events
WeatherKit moon event types.
prelude
Common imports.
pressure
WeatherKit pressure types.
service
WeatherKit service types and query helpers.
statistics
WeatherKit statistics and summary types.
sun_events
WeatherKit sun event types.
weather
Convenient WeatherKit weather re-exports.
weather_alert
WeatherKit weather alert types.
weather_attribution
WeatherKit attribution types.
weather_condition
WeatherKit condition and precipitation enums.