{
  "$type": "site.standard.document",
  "bskyPostRef": {
    "cid": "bafyreid24pxkrb4docsvaq6t3nslmbyss4paxpbrj7v45i26kb4drsg4ka",
    "uri": "at://did:plc:ivbknywyskln22er3nkssdhl/app.bsky.feed.post/3mnfipaq44mu2"
  },
  "path": "/t/possibility-of-a-global-time-source-for-wasm-targets/24370#post_1",
  "publishedAt": "2026-06-03T14:46:22.000Z",
  "site": "https://internals.rust-lang.org",
  "textContent": "My idea is having something like the `#[global_allocator]` macro but for a \"time source\", and have `std::time::Instant::now()` use it.\n\nRight 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\n\n\n    #[global_allocator]\n    static GLOBAL: MiMalloc = MiMalloc;\n\n    #[cfg(target_arch = \"wasm32\")]\n    #[global_time_source]\n    static CLOCK: web_time::Clock = web_time::Clock;\n    // static CLOCK: wasmtimer::Clock = wasmtimer::Clock;\n\n    fn main() {\n        std::time::Instant::now();\n    }\n",
  "title": "Possibility of a \"global time source\" for wasm targets"
}