pub struct AsyncWeatherService { /* private fields */ }async only.Expand description
Async wrapper around WeatherService.
Create one with AsyncWeatherService::shared() or
AsyncWeatherService::new(), then call any of its methods to get a
Future. The futures are executor-agnostic — use pollster, Tokio,
async-std, or any other runtime.
§Example
use weatherkit::async_api::AsyncWeatherService;
use weatherkit::service::CLLocation;
pollster::block_on(async {
let svc = AsyncWeatherService::shared();
let sf = CLLocation::new(37.7749, -122.4194);
let weather = svc.weather(&sf).await
.map_err(|e| Box::new(e) as Box<dyn std::error::Error>)?;
println!("Condition: {:?}", weather.current_weather.condition);
Ok::<_, Box<dyn std::error::Error>>(())
})Implementations§
Source§impl AsyncWeatherService
impl AsyncWeatherService
Use the shared WeatherService singleton.
Sourcepub fn weather(&self, location: &CLLocation) -> WeatherFuture ⓘ
pub fn weather(&self, location: &CLLocation) -> WeatherFuture ⓘ
Fetch the full Weather bundle.
Wraps WeatherService.weather(for:) async throws.
§Errors
Returns a WeatherKitError if the app lacks a valid WeatherKit
entitlement or if the network request fails.
Sourcepub fn current_weather(&self, location: &CLLocation) -> CurrentWeatherFuture ⓘ
pub fn current_weather(&self, location: &CLLocation) -> CurrentWeatherFuture ⓘ
Fetch only the current conditions.
Wraps WeatherService.weather(for: including: .current) async throws.
Sourcepub fn hourly_forecast(&self, location: &CLLocation) -> HourlyForecastFuture ⓘ
pub fn hourly_forecast(&self, location: &CLLocation) -> HourlyForecastFuture ⓘ
Fetch the hourly forecast.
Wraps WeatherService.weather(for: including: .hourly) async throws.
Sourcepub fn hourly_forecast_in(
&self,
location: &CLLocation,
interval: DateInterval,
) -> HourlyForecastFuture ⓘ
pub fn hourly_forecast_in( &self, location: &CLLocation, interval: DateInterval, ) -> HourlyForecastFuture ⓘ
Fetch the hourly forecast for a specific date interval.
Wraps WeatherService.weather(for: including: .hourly(startDate:endDate:)) async throws.
Sourcepub fn daily_forecast(&self, location: &CLLocation) -> DailyForecastFuture ⓘ
pub fn daily_forecast(&self, location: &CLLocation) -> DailyForecastFuture ⓘ
Fetch the daily forecast.
Wraps WeatherService.weather(for: including: .daily) async throws.
Sourcepub fn daily_forecast_in(
&self,
location: &CLLocation,
interval: DateInterval,
) -> DailyForecastFuture ⓘ
pub fn daily_forecast_in( &self, location: &CLLocation, interval: DateInterval, ) -> DailyForecastFuture ⓘ
Fetch the daily forecast for a specific date interval.
Wraps WeatherService.weather(for: including: .daily(startDate:endDate:)) async throws.
Sourcepub fn minute_forecast(&self, location: &CLLocation) -> MinuteForecastFuture ⓘ
pub fn minute_forecast(&self, location: &CLLocation) -> MinuteForecastFuture ⓘ
Fetch the minute-by-minute precipitation forecast.
Wraps WeatherService.weather(for: including: .minute) async throws.
Returns None if minute forecast is not available for the location.
Sourcepub fn weather_alerts(&self, location: &CLLocation) -> WeatherAlertsFuture ⓘ
pub fn weather_alerts(&self, location: &CLLocation) -> WeatherAlertsFuture ⓘ
Fetch weather alerts for the location.
Wraps WeatherService.weather(for: including: .alerts) async throws.
Sourcepub fn availability(&self, location: &CLLocation) -> AvailabilityFuture ⓘ
pub fn availability(&self, location: &CLLocation) -> AvailabilityFuture ⓘ
Fetch data-availability information for the location.
Wraps WeatherService.weather(for: including: .availability) async throws.
Sourcepub fn attribution(&self) -> AttributionFuture ⓘ
pub fn attribution(&self) -> AttributionFuture ⓘ
Fetch the WeatherKit attribution metadata required to be displayed in your UI.
Wraps WeatherService.attribution async throws.
Sourcepub fn weather_changes(&self, location: &CLLocation) -> WeatherChangesFuture ⓘ
pub fn weather_changes(&self, location: &CLLocation) -> WeatherChangesFuture ⓘ
Fetch weather-change forecasts (macOS 15.0+).
Wraps WeatherService.weather(for: including: .changes) async throws.
Returns an error on macOS < 15.0.
Sourcepub fn historical_comparisons(
&self,
location: &CLLocation,
) -> HistoricalComparisonsFuture ⓘ
pub fn historical_comparisons( &self, location: &CLLocation, ) -> HistoricalComparisonsFuture ⓘ
Fetch historical weather comparisons (macOS 15.0+).
Wraps WeatherService.weather(for: including: .historicalComparisons) async throws.
Returns an error on macOS < 15.0.
Trait Implementations§
Source§impl Clone for AsyncWeatherService
impl Clone for AsyncWeatherService
Source§fn clone(&self) -> AsyncWeatherService
fn clone(&self) -> AsyncWeatherService
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more