Possibility of a "global time source" for wasm targets
Rust Internals [Unofficial]
June 3, 2026
My idea is having something like the #[global_allocator] macro but for a "time source", and have std::time::Instant::now() use it.
Right now whenever we need to use time on wasm we replace uses of std::time::Instant for a type defined on wasmtimer, web-time, etc, with my suggestion maybe it would be possible to have those crates provide a type that can be used with a #[global_time_source] macro and have std::time::Instant take the time from there
#[global_allocator]
static GLOBAL: MiMalloc = MiMalloc;
#[cfg(target_arch = "wasm32")]
#[global_time_source]
static CLOCK: web_time::Clock = web_time::Clock;
// static CLOCK: wasmtimer::Clock = wasmtimer::Clock;
fn main() {
std::time::Instant::now();
}
Discussion in the ATmosphere