web-time
A complete drop-in replacement for Rust's std::time that works in browsers on the Wasm target.
Repository Health
Technical Analysis
web-time is a Rust crate that provides a complete drop-in replacement for std::time on the wasm32-unknown-unknown target, where the standard library’s Instant::now() and SystemTime::now() otherwise panic. It backs Instant with the browser’s Performance.now() and SystemTime with Date.now(), so time-based code that assumes std::time keeps working inside the browser.
Crucially, on any non-Wasm target the crate simply re-exports std::time and pulls in zero dependencies, making it a cost-free import for cross-platform libraries. When compiled with atomics enabled it also synchronizes timestamps across execution contexts such as web workers using Performance.timeOrigin.
What You Get
- Working Instant and SystemTime implementations for the wasm32-unknown-unknown and wasm32v1-none targets
- An API surface identical to std::time, so migration is a one-line import change
- Zero dependencies and a plain re-export of std::time on all non-Wasm targets
- Optional serde support and cross-context timestamp synchronization under target-feature = “atomics”
Common Use Cases
- Running timing, benchmarking, or scheduling code compiled to Wasm in the browser
- Writing cross-platform Rust libraries that must not panic when built for the web
- Measuring elapsed time with Instant inside wasm-bindgen browser applications
- Serializing SystemTime values with serde in Wasm builds
Under The Hood
Architecture The crate is organized under src/time/ with separate modules for instant.rs, system_time.rs, a js.rs binding layer, and optional serde.rs. Conditional compilation (cfg(all(target_arch = "wasm32", any(target_os = "unknown", target_os = "none")))) selects the browser-backed implementation; on every other target lib.rs re-exports std::time directly. The Wasm implementation calls Performance.now()/Date.now() through wasm-bindgen and, under the atomics feature, adjusts against Performance.timeOrigin to keep timestamps consistent across contexts.
Tech Stack It is a Rust crate (edition 2021, MSRV 1.60) that depends only on wasm-bindgen (and optional serde) on the Wasm target, with rustversion as a build dependency for MSRV handling. A Cargo workspace bundles dedicated test crates (tests-native, tests-web) and there are benches, so cross-target correctness is exercised deliberately.
Code Quality The project shows strong discipline: a clippy.toml, rustfmt.toml, taplo.toml, CONTRIBUTING guide, changelog, and separate native/web/crate integration-test suites plus published coverage. Feature flags and target gates are carefully scoped so the crate is genuinely zero-cost off Wasm.
API Design Because the crate deliberately mirrors std::time one-to-one, there is essentially nothing new to learn—the API is whatever a Rust developer already knows from the standard library. Adoption is a single import path change, which makes the learning curve minimal and the ergonomics excellent for its narrow purpose.
Used by 2 apps in this directory
liteparse
Developer Tools
A fast, lightweight, open-source document parser that extracts spatial text, bounding boxes, and Markdown from PDFs and Office files — entirely on your machine.
Zed
Developer Tools · Collaboration · Code Editors
High-performance, multiplayer code editor built in Rust by the creators of Atom and Tree-sitter, with native AI integration and real-time collaboration.