From 14d1f05129cc3a10529cb50ed1910787735faca0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Kijewski?= Date: Fri, 22 Jul 2022 17:36:19 +0200 Subject: [PATCH] Support iOS, don't compile error if unsupported Cf. https://github.com/baoyachi/shadow-rs/pull/107#issuecomment-1192489565 --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/lib.rs | 23 ++++++++++++++--------- src/platform.rs | 7 +------ 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b6840b2..c93ae8b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -42,7 +42,7 @@ checksum = "5827cebf4670468b8772dd191856768aedcb1b0278a04f989f7766351917b9dc" [[package]] name = "iana-time-zone" -version = "0.1.35" +version = "0.1.36" dependencies = [ "core-foundation", "js-sys", diff --git a/Cargo.toml b/Cargo.toml index 68177ad..c863e06 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,7 +10,7 @@ categories = ["date-and-time", "internationalization", "os"] readme = "README.md" edition = "2018" -[target.'cfg(target_os = "macos")'.dependencies] +[target.'cfg(any(target_os = "macos", target_os = "ios"))'.dependencies] core-foundation = "0.9" [target.'cfg(target_os = "windows")'.dependencies] diff --git a/src/lib.rs b/src/lib.rs index eda970d..fd45905 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -20,7 +20,10 @@ #[cfg_attr(target_os = "linux", path = "tz_linux.rs")] #[cfg_attr(target_os = "windows", path = "tz_windows.rs")] -#[cfg_attr(target_os = "macos", path = "tz_macos.rs")] +#[cfg_attr( + any(target_os = "macos", target_os = "ios"), + path = "tz_macos.rs" +)] #[cfg_attr( all(target_arch = "wasm32", not(target_os = "wasi")), path = "tz_wasm32.rs" @@ -44,20 +47,21 @@ pub enum GetTimezoneError { IoError(std::io::Error), /// Platform-specific error from the operating system OsError, + /// Unsupported target OS + Unsupported, } impl std::error::Error for GetTimezoneError {} impl std::fmt::Display for GetTimezoneError { fn fmt(&self, f: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> { - use GetTimezoneError::*; - let descr = match self { - FailedParsingString => "GetTimezoneError::FailedParsingString", - IoError(_) => "GetTimezoneError::IoError(_)", - OsError => "OsError", - }; - - write!(f, "{}", descr) + f.write_str(match self { + Self::FailedParsingString => "GetTimezoneError::FailedParsingString", + Self::IoError(err) => return err.fmt(f), + Self::OsError => "OsError", + Self::Unsupported => "Unsupported operating system, \ + please file a bug report to iana-time-zone", + }) } } @@ -71,6 +75,7 @@ impl std::convert::From for GetTimezoneError { /// /// See the module-level documentatation for a usage example and more details /// about this function. +#[inline] pub fn get_timezone() -> std::result::Result { platform::get_timezone_inner() } diff --git a/src/platform.rs b/src/platform.rs index f40f6d0..8d1fe56 100644 --- a/src/platform.rs +++ b/src/platform.rs @@ -1,8 +1,3 @@ pub fn get_timezone_inner() -> std::result::Result { - Err(crate::GetTimezoneError::FailedParsingString) + Err(crate::GetTimezoneError::Unsupported) } - -compile_error!( - "iana-time-zone is currently implemented for Linux, Window, MacOS, FreeBSD, NetBSD, \ - OpenBSD, Dragonfly, and WebAssembly (browser).", -);