Skip to main content

02_current_weather_snapshot/support/
mod.rs

1#![allow(dead_code)]
2
3use std::error::Error;
4
5use weatherkit::{CLLocation, WeatherKitError};
6
7pub const fn sample_location() -> CLLocation {
8    CLLocation::new(37.3349, -122.0090)
9}
10
11pub fn handle_result<T>(
12    area: &str,
13    result: Result<T, WeatherKitError>,
14) -> Result<Option<T>, Box<dyn Error>> {
15    match result {
16        Ok(value) => Ok(Some(value)),
17        Err(error) if error.is_entitlement_issue() => {
18            println!("weatherkit {area}: entitled bundle ID required; treating as caveat");
19            Ok(None)
20        }
21        Err(error) => Err(Box::new(error)),
22    }
23}
24
25pub fn finish(area: &str) {
26    println!("✅ {area}");
27}