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.2.1 covers the full non-exempt macOS WeatherKit surface, including WeatherService multi-query helpers, statistics/summaries, weather changes, historical comparisons, and enum descriptor catalogs.

§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(())
}

§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.

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§

availability_kind
changes
current_weather
daily_forecast
error
ffi
hourly_forecast
minute_forecast
moon_events
prelude
Common imports.
pressure
service
statistics
sun_events
weather
weather_alert
weather_attribution
weather_condition