Skip to main content

Module async_api

Module async_api 

Source
Available on crate feature async only.
Expand description

Async API for WeatherKit — executor-agnostic Future wrappers.

Enabled with the async Cargo feature. Every Apple async throws surface on WeatherService gets a corresponding Future newtype here. The pattern follows the doom-fish gold standard from screencapturekit-rs: a @_cdecl Swift thunk launches a Swift Task, fires a C callback on completion, and the Rust side wraps the call in an AsyncCompletionFuture via doom_fish_utils::completion::AsyncCompletion.

§Available Future types

Future typeSwift API
WeatherFutureWeatherService.weather(for:)
CurrentWeatherFutureWeatherService.weather(for: including: .current)
HourlyForecastFutureWeatherService.weather(for: including: .hourly)
DailyForecastFutureWeatherService.weather(for: including: .daily)
MinuteForecastFutureWeatherService.weather(for: including: .minute)
WeatherAlertsFutureWeatherService.weather(for: including: .alerts)
AvailabilityFutureWeatherService.weather(for: including: .availability)
AttributionFutureWeatherService.attribution
WeatherChangesFutureWeatherService.weather(for: including: .changes) (macOS 15+)
HistoricalComparisonsFutureWeatherService.weather(for: including: .historicalComparisons) (macOS 15+)

§Tier-2 note (streams / KVO)

WeatherChange / WeatherUpdate multi-fire observation and server-sent-event style APIs are deferred to Tier 2 (async Stream pattern).

§Example

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

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::<_, Box<dyn std::error::Error>>(())
})

Structs§

AsyncWeatherService
Async wrapper around WeatherService.
AttributionFuture
Future returned by AsyncWeatherService::attribution.
AvailabilityFuture
Future returned by AsyncWeatherService::availability.
CurrentWeatherFuture
Future returned by AsyncWeatherService::current_weather.
DailyForecastFuture
Future returned by AsyncWeatherService::daily_forecast and AsyncWeatherService::daily_forecast_in.
HistoricalComparisonsFuture
Future returned by AsyncWeatherService::historical_comparisons.
HourlyForecastFuture
Future returned by AsyncWeatherService::hourly_forecast and AsyncWeatherService::hourly_forecast_in.
MinuteForecastFuture
Future returned by AsyncWeatherService::minute_forecast.
WeatherAlertsFuture
Future returned by AsyncWeatherService::weather_alerts.
WeatherChangesFuture
Future returned by AsyncWeatherService::weather_changes.
WeatherFuture
Future returned by AsyncWeatherService::weather.