From ac83e3b0e1330c9ced79c98fc9582bd9c17e70d2 Mon Sep 17 00:00:00 2001 From: DanGould Date: Fri, 9 Feb 2024 20:13:01 -0500 Subject: [PATCH] Supply `instant::SystemTime` for wasm32 `std::time::SystemTime` is unavailable in wasm32-unknown-unknown. --- Cargo.toml | 3 +++ src/lib.rs | 6 ++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 2a392c0..dfd0f6c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,6 +15,9 @@ default = ["alloc"] alloc = [] std = ["alloc"] +[target.'cfg(target_arch = "wasm32")'.dependencies] +instant = "0.1" + [package.metadata.docs.rs] all-features = true rustdoc-args = ["--cfg", "docsrs"] diff --git a/src/lib.rs b/src/lib.rs index 5832336..7af2351 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -52,7 +52,9 @@ use alloc::vec::Vec; use core::fmt; use core::ops::Deref; use core::time::Duration; -#[cfg(feature = "std")] +#[cfg(target_arch = "wasm32")] +use instant::SystemTime; +#[cfg(all(feature = "std", not(target_arch = "wasm32")))] use std::time::SystemTime; mod server_name; @@ -478,7 +480,7 @@ pub struct UnixTime(u64); impl UnixTime { /// The current time, as a `UnixTime` - #[cfg(feature = "std")] + #[cfg(any(feature = "std", target_arch = "wasm32"))] pub fn now() -> Self { Self::since_unix_epoch( SystemTime::now()