Expand description
§web-time-compat
Small compatibility layer for web-time.
Unlike web-time, this crate does not require you to stop using
std::time::SystemTime.
Instead, it provides an extension trait to replace the now
method of SystemTime types with a get method that works on
wasm32-unknown-unknown.
With Instant, it isn’t possible to continue using std::time::Instant,
since that type is not interconvertible with web_time::Instant. Instead,
we provide an extension trait to make it easier for you to make sure that you
are only using the version of Instant you want.
§How to use this crate
(This isn’t the only way, but it’s what we recommend.)
- Replace all references to
std::time::Instantwithweb_time_compat::Instant. - You may, if you like, also use
web_time_compat::{Duration, SystemTime}. They are just aliases for the standard Duration and SystemTimetypes. - Instead of
SystemTime::now(), useSystemTimeExt::get(). - Instead of
Instant::now(), useInstant::get(). - Add
std::time::SystemTime::nowandstd::time::Instant::nowto yourdisallowed-methodslist in yourclippy.tomlfile, to prevent them from being used accidentally. - If you use any other time libraries (such as
timeorchrono), you may want to add their “now” methods todisallowed-methods, depending on whether you have configured them for wasm compatibility.
License: MIT OR Apache-2.0
Modules§
Structs§
- Duration
- A
Durationtype to represent a span of time, typically used for system timeouts. - Instant
- A measurement of a monotonically nondecreasing clock.
Opaque and useful only with
Duration. - System
Time - A measurement of the system clock, useful for talking to external entities like the file system or other processes.
Traits§
- Instant
Ext - Extension trait for
Instant. - System
Time Ext - Extension trait for
std::time::SystemTime