Skip to content

Commit

Permalink
Supply instant::SystemTime for wasm32
Browse files Browse the repository at this point in the history
`std::time::SystemTime` is unavailable in wasm32-unknown-unknown.
  • Loading branch information
DanGould committed Feb 10, 2024
1 parent 386d084 commit be2f071
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
6 changes: 4 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,10 @@ use alloc::vec::Vec;
use core::fmt;
use core::ops::Deref;
use core::time::Duration;
#[cfg(feature = "std")]
#[cfg(all(feature = "std", not(target_arch = "wasm32")))]
use std::time::SystemTime;
#[cfg(target_arch = "wasm32")]
use instant::SystemTime;

mod server_name;
pub use server_name::{
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit be2f071

Please sign in to comment.