Skip to main content

AsyncWeatherService

Struct AsyncWeatherService 

Source
pub struct AsyncWeatherService { /* private fields */ }
Available on crate feature 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

Source

pub const fn shared() -> Self

Use the shared WeatherService singleton.

Source

pub const fn new() -> Self

Create a new WeatherService instance.

Source

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.

Source

pub fn current_weather(&self, location: &CLLocation) -> CurrentWeatherFuture

Fetch only the current conditions.

Wraps WeatherService.weather(for: including: .current) async throws.

Source

pub fn hourly_forecast(&self, location: &CLLocation) -> HourlyForecastFuture

Fetch the hourly forecast.

Wraps WeatherService.weather(for: including: .hourly) async throws.

Source

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.

Source

pub fn daily_forecast(&self, location: &CLLocation) -> DailyForecastFuture

Fetch the daily forecast.

Wraps WeatherService.weather(for: including: .daily) async throws.

Source

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.

Source

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.

Source

pub fn weather_alerts(&self, location: &CLLocation) -> WeatherAlertsFuture

Fetch weather alerts for the location.

Wraps WeatherService.weather(for: including: .alerts) async throws.

Source

pub fn availability(&self, location: &CLLocation) -> AvailabilityFuture

Fetch data-availability information for the location.

Wraps WeatherService.weather(for: including: .availability) async throws.

Source

pub fn attribution(&self) -> AttributionFuture

Fetch the WeatherKit attribution metadata required to be displayed in your UI.

Wraps WeatherService.attribution async throws.

Source

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.

Source

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

Source§

fn clone(&self) -> AsyncWeatherService

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for AsyncWeatherService

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for AsyncWeatherService

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Copy for AsyncWeatherService

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.