instant
A std::time::Instant replacement that also works on WASM targets
Repository Health
Technical Analysis
instant is a small Rust crate that provides a partial replacement for std::time::Instant that works on WebAssembly. Calling std::time::Instant::now() panics on wasm32-unknown-unknown, and instant fixes this by emulating the type using the JavaScript performance.now() function when targeting WASM.
On all non-WASM platforms instant::Instant is simply a type alias for std::time::Instant, so code written against it behaves identically. The crate is now unmaintained and its author recommends migrating to web-time, but it remains widely depended upon across the ecosystem.
What You Get
- A drop-in
Instanttype that compiles and runs on WASM - Transparent aliasing to std::time::Instant on native platforms
- Feature flags for wasm-bindgen and stdweb backends
- A tiny dependency footprint (only cfg-if on native)
- Optional now and inaccurate feature modes
Common Use Cases
- Measuring elapsed time in Rust code that also targets the browser via WASM
- Sharing timing logic between native and WebAssembly builds
- Porting existing crates that use std::time::Instant to WASM
- Frame timing and animation loops in wasm-bindgen applications
Under The Hood
Architecture — instant is a single-purpose crate whose src/lib.rs uses cfg-if to select between a plain re-export of std::time::Instant on native targets and a WASM emulation module that wraps performance.now() through js-sys/web-sys or stdweb. Tech Stack — Rust edition 2018 with only cfg-if as a mandatory dependency and optional js-sys, web-sys, wasm-bindgen, and stdweb dependencies gated to wasm32 targets. Code Quality — The crate is intentionally minimal and stable, though it is now marked unmaintained (“looking-for-maintainer”) with the README pointing users to web-time. API Design — Because the public type mirrors std::time::Instant exactly, adoption requires only swapping the import path, which is the crate’s core ergonomic advantage.