web-time-compat 0.1.0

Compatibility layer for web-time
Documentation
  • Coverage
  • 100%
    5 out of 5 items documented0 out of 4 items with examples
  • Size
  • Source code size: 12.35 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 3.01 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 20s Average build duration of successful builds.
  • all releases: 20s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • Repository
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • ijackson

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