Winit: Instant is not available on WASM + Proposed Solution

Created on 15 Jun 2019  路  3Comments  路  Source: rust-windowing/winit

Instant is part of the public API of EventLoop 2.0, which makes sense but unfortunately Instant cannot be constructed on WASM. As of right now, wasm (via stdweb or wasm-bindgen) is essentially only able to access core and alloc.

One solution is to wait until Instant becomes available on wasm via the experimental system call interface. However, there is no timeline for this and it's not clear how long that will take.

What I propose is winit have its own Instant type, with an API identical to std::time::Instant, except it has a private constructor that allows wasm to construct instances of it from web time APIs. The upside is that the public API is more or less the same and fully compatible with wasm; the downside is that users may be confused about why winit has its own Instant type. A possible fix for that would be to intentionally change the type's name to a synonym like Timestamp, so that it is obviously distinct from the type in the standard library.

I would be willing to make the change as part of #797 as long as the maintainers of other platforms would be amenable to it.

Most helpful comment

I think the instant crate exists for this purpose, that is to get the same behaviour as std Instant that also works on WASM.

All 3 comments

I think the instant crate exists for this purpose, that is to get the same behaviour as std Instant that also works on WASM.

Looks like it, and maintained by a fairly prominent author. That鈥檚 probably the best solution then, if it鈥檚 amenable to everyone.

Okay, Instant required minimal changes on the stdweb branch. Any future discussion is probably best there.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rukai picture rukai  路  4Comments

hobogenized picture hobogenized  路  3Comments

chrisduerr picture chrisduerr  路  3Comments

chemicstry picture chemicstry  路  3Comments

coderhwz picture coderhwz  路  3Comments