Skip to main content

Crate web_time_compat

Crate web_time_compat 

Source
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::Instant with web_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(), use SystemTimeExt::get().
  • Instead of Instant::now(), use Instant::get().
  • Add std::time::SystemTime::now and std::time::Instant::now to your disallowed-methods list in your clippy.toml file, to prevent them from being used accidentally.
  • If you use any other time libraries (such as time or chrono), you may want to add their “now” methods to disallowed-methods, depending on whether you have configured them for wasm compatibility.

License: MIT OR Apache-2.0

Modules§

seal 🔒
Module to hide “Sealed”
stdlib 🔒
Standard-library time functionality..

Structs§

Duration
A Duration type 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.
SystemTime
A measurement of the system clock, useful for talking to external entities like the file system or other processes.

Traits§

InstantExt
Extension trait for Instant.
SystemTimeExt
Extension trait for std::time::SystemTime