instant

A std::time::Instant replacement that also works on WASM targets

Library
Cargo
v0.1.13
116stars
BSD 3-Clause License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
39/100Needs Attention
Development Activity0
Maintenance0
Community76
Maturity60
Momentum20

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
74/100Good
Architecture72
Code Quality70
Innovation64
Learning Curve90

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 Instant type 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.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search