Skip to main content

WeatherService

Struct WeatherService 

Source
pub struct WeatherService { /* private fields */ }

Implementations§

Source§

impl WeatherService

Source

pub const fn shared() -> Self

Examples found in repository?
examples/09_sun_events_snapshot.rs (line 9)
8fn main() -> Result<(), Box<dyn Error>> {
9    let service = WeatherService::shared();
10    let location = support::sample_location();
11
12    if let Some(sun) = support::handle_result("sun events", service.sun_events(&location))? {
13        println!("sunrise={:?} sunset={:?}", sun.sunrise, sun.sunset);
14    }
15
16    support::finish("sun events");
17    Ok(())
18}
More examples
Hide additional examples
examples/08_weather_attribution_snapshot.rs (line 9)
8fn main() -> Result<(), Box<dyn Error>> {
9    let service = WeatherService::shared();
10
11    if let Some(attribution) = support::handle_result("weather attribution", service.attribution())?
12    {
13        println!(
14            "service={} legal_page={}",
15            attribution.service_name, attribution.legal_page_url
16        );
17    }
18
19    support::finish("weather attribution");
20    Ok(())
21}
examples/10_moon_events_snapshot.rs (line 9)
8fn main() -> Result<(), Box<dyn Error>> {
9    let service = WeatherService::shared();
10    let location = support::sample_location();
11
12    if let Some(moon) = support::handle_result("moon events", service.moon_events(&location))? {
13        println!(
14            "phase={:?} moonrise={:?} moonset={:?}",
15            moon.phase, moon.moonrise, moon.moonset
16        );
17    }
18
19    support::finish("moon events");
20    Ok(())
21}
examples/05_weather_alerts_snapshot.rs (line 9)
8fn main() -> Result<(), Box<dyn Error>> {
9    let service = WeatherService::shared();
10    let location = support::sample_location();
11
12    if let Some(alerts) =
13        support::handle_result("weather alerts", service.weather_alerts(&location))?
14    {
15        let first_severity = alerts.first().map(WeatherAlert::severity_kind);
16        println!("alerts={} first_severity={first_severity:?}", alerts.len());
17    }
18
19    support::finish("weather alerts");
20    Ok(())
21}
examples/01_weather_service_smoke.rs (line 9)
8fn main() -> Result<(), Box<dyn Error>> {
9    let service = WeatherService::shared();
10    let location = support::sample_location();
11
12    if let Some(weather) = support::handle_result("weather service", service.weather(&location))? {
13        println!(
14            "current={:.1}°C hourly={} daily={} alerts={}",
15            weather.current_weather.temperature,
16            weather.hourly_forecast.len(),
17            weather.daily_forecast.len(),
18            weather.weather_alerts.len()
19        );
20    }
21
22    support::finish("weather service");
23    Ok(())
24}
examples/02_current_weather_snapshot.rs (line 9)
8fn main() -> Result<(), Box<dyn Error>> {
9    let service = WeatherService::shared();
10    let location = support::sample_location();
11
12    if let Some(current) =
13        support::handle_result("current weather", service.current_weather(&location))?
14    {
15        println!(
16            "temp={:.1}°C feels_like={:.1}°C pressure={:.1}hPa daylight={}",
17            current.temperature,
18            current.feels_like,
19            current.pressure_reading().value,
20            current.is_daylight
21        );
22    }
23
24    support::finish("current weather");
25    Ok(())
26}
Source

pub const fn new() -> Self

Source

pub fn attribution(&self) -> Result<WeatherAttribution, WeatherKitError>

Examples found in repository?
examples/08_weather_attribution_snapshot.rs (line 11)
8fn main() -> Result<(), Box<dyn Error>> {
9    let service = WeatherService::shared();
10
11    if let Some(attribution) = support::handle_result("weather attribution", service.attribution())?
12    {
13        println!(
14            "service={} legal_page={}",
15            attribution.service_name, attribution.legal_page_url
16        );
17    }
18
19    support::finish("weather attribution");
20    Ok(())
21}
Source

pub fn weather(&self, location: &CLLocation) -> Result<Weather, WeatherKitError>

Examples found in repository?
examples/01_weather_service_smoke.rs (line 12)
8fn main() -> Result<(), Box<dyn Error>> {
9    let service = WeatherService::shared();
10    let location = support::sample_location();
11
12    if let Some(weather) = support::handle_result("weather service", service.weather(&location))? {
13        println!(
14            "current={:.1}°C hourly={} daily={} alerts={}",
15            weather.current_weather.temperature,
16            weather.hourly_forecast.len(),
17            weather.daily_forecast.len(),
18            weather.weather_alerts.len()
19        );
20    }
21
22    support::finish("weather service");
23    Ok(())
24}
More examples
Hide additional examples
examples/01_weather_smoke.rs (line 7)
3fn main() -> Result<(), Box<dyn std::error::Error>> {
4    let service = WeatherService::shared();
5    let location = CLLocation::new(37.3349, -122.0090);
6
7    match service.weather(&location) {
8        Ok(weather) => {
9            println!(
10                "current temperature: {:.1}°C",
11                weather.current_weather.temperature
12            );
13        }
14        Err(error) if error.is_entitlement_issue() => {
15            eprintln!("weatherkit requires entitled bundle ID; check developer.apple.com/account");
16        }
17        Err(error) => return Err(error.into()),
18    }
19
20    println!("✅ weatherkit smoke (with caveats)");
21    Ok(())
22}
Source

pub fn current_weather( &self, location: &CLLocation, ) -> Result<CurrentWeather, WeatherKitError>

Examples found in repository?
examples/02_current_weather_snapshot.rs (line 13)
8fn main() -> Result<(), Box<dyn Error>> {
9    let service = WeatherService::shared();
10    let location = support::sample_location();
11
12    if let Some(current) =
13        support::handle_result("current weather", service.current_weather(&location))?
14    {
15        println!(
16            "temp={:.1}°C feels_like={:.1}°C pressure={:.1}hPa daylight={}",
17            current.temperature,
18            current.feels_like,
19            current.pressure_reading().value,
20            current.is_daylight
21        );
22    }
23
24    support::finish("current weather");
25    Ok(())
26}
Source

pub fn hourly_forecast( &self, location: &CLLocation, ) -> Result<HourlyForecast, WeatherKitError>

Examples found in repository?
examples/04_hourly_forecast_snapshot.rs (line 13)
8fn main() -> Result<(), Box<dyn Error>> {
9    let service = WeatherService::shared();
10    let location = support::sample_location();
11
12    if let Some(hourly) =
13        support::handle_result("hourly forecast", service.hourly_forecast(&location))?
14    {
15        if let Some(first) = hourly.forecast.first() {
16            println!(
17                "first_hour={} temp={:.1}°C precip={:?} wind={:.1}m/s",
18                first.date, first.temperature, first.precipitation, first.wind.speed
19            );
20        } else {
21            println!("hourly forecast returned no hours");
22        }
23    }
24
25    support::finish("hourly forecast");
26    Ok(())
27}
Source

pub fn hourly_forecast_in( &self, location: &CLLocation, interval: DateInterval, ) -> Result<HourlyForecast, WeatherKitError>

Source

pub fn daily_forecast( &self, location: &CLLocation, ) -> Result<DailyForecast, WeatherKitError>

Examples found in repository?
examples/03_daily_forecast_snapshot.rs (line 13)
8fn main() -> Result<(), Box<dyn Error>> {
9    let service = WeatherService::shared();
10    let location = support::sample_location();
11
12    if let Some(daily) =
13        support::handle_result("daily forecast", service.daily_forecast(&location))?
14    {
15        if let Some(first) = daily.forecast.first() {
16            println!(
17                "first_day={} high={:.1}°C low={:.1}°C sunrise={:?}",
18                first.date, first.high_temperature, first.low_temperature, first.sun.sunrise
19            );
20        } else {
21            println!("daily forecast returned no days");
22        }
23    }
24
25    support::finish("daily forecast");
26    Ok(())
27}
Source

pub fn daily_forecast_in( &self, location: &CLLocation, interval: DateInterval, ) -> Result<DailyForecast, WeatherKitError>

Source

pub fn minute_forecast( &self, location: &CLLocation, ) -> Result<Option<MinuteForecastCollection>, WeatherKitError>

Examples found in repository?
examples/06_minute_forecast_snapshot.rs (line 13)
8fn main() -> Result<(), Box<dyn Error>> {
9    let service = WeatherService::shared();
10    let location = support::sample_location();
11
12    if let Some(minute) =
13        support::handle_result("minute forecast", service.minute_forecast(&location))?
14    {
15        if let Some(minute) = minute {
16            println!(
17                "summary={} entries={}",
18                minute.summary,
19                minute.forecast.len()
20            );
21        } else {
22            println!("minute forecast unavailable for this location");
23        }
24    }
25
26    support::finish("minute forecast");
27    Ok(())
28}
Source

pub fn weather_alerts( &self, location: &CLLocation, ) -> Result<Vec<WeatherAlert>, WeatherKitError>

Examples found in repository?
examples/05_weather_alerts_snapshot.rs (line 13)
8fn main() -> Result<(), Box<dyn Error>> {
9    let service = WeatherService::shared();
10    let location = support::sample_location();
11
12    if let Some(alerts) =
13        support::handle_result("weather alerts", service.weather_alerts(&location))?
14    {
15        let first_severity = alerts.first().map(WeatherAlert::severity_kind);
16        println!("alerts={} first_severity={first_severity:?}", alerts.len());
17    }
18
19    support::finish("weather alerts");
20    Ok(())
21}
Source

pub fn availability( &self, location: &CLLocation, ) -> Result<WeatherAvailability, WeatherKitError>

Source

pub fn sun_events( &self, location: &CLLocation, ) -> Result<SunEvents, WeatherKitError>

Examples found in repository?
examples/09_sun_events_snapshot.rs (line 12)
8fn main() -> Result<(), Box<dyn Error>> {
9    let service = WeatherService::shared();
10    let location = support::sample_location();
11
12    if let Some(sun) = support::handle_result("sun events", service.sun_events(&location))? {
13        println!("sunrise={:?} sunset={:?}", sun.sunrise, sun.sunset);
14    }
15
16    support::finish("sun events");
17    Ok(())
18}
Source

pub fn moon_events( &self, location: &CLLocation, ) -> Result<MoonEvents, WeatherKitError>

Examples found in repository?
examples/10_moon_events_snapshot.rs (line 12)
8fn main() -> Result<(), Box<dyn Error>> {
9    let service = WeatherService::shared();
10    let location = support::sample_location();
11
12    if let Some(moon) = support::handle_result("moon events", service.moon_events(&location))? {
13        println!(
14            "phase={:?} moonrise={:?} moonset={:?}",
15            moon.phase, moon.moonrise, moon.moonset
16        );
17    }
18
19    support::finish("moon events");
20    Ok(())
21}
Source

pub fn pressure( &self, location: &CLLocation, ) -> Result<Pressure, WeatherKitError>

Examples found in repository?
examples/12_pressure_catalog.rs (line 20)
8fn main() -> Result<(), Box<dyn Error>> {
9    let descriptors = PressureTrend::descriptors()?;
10    println!(
11        "pressure_trends={:?}",
12        descriptors
13            .iter()
14            .map(|d| d.raw_value.as_str())
15            .collect::<Vec<_>>()
16    );
17
18    let service = WeatherService::shared();
19    let location = support::sample_location();
20    if let Some(pressure) = support::handle_result("pressure", service.pressure(&location))? {
21        println!(
22            "current_pressure={:.1}hPa trend={:?}",
23            pressure.value, pressure.trend
24        );
25    }
26
27    support::finish("pressure");
28    Ok(())
29}

Trait Implementations§

Source§

impl Clone for WeatherService

Source§

fn clone(&self) -> WeatherService

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 WeatherService

Source§

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

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

impl Default for WeatherService

Source§

fn default() -> WeatherService

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

impl Copy for WeatherService

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.