web_instant 0.3.0

Cross platform impl of Instant
Documentation
  • Coverage
  • 50%
    1 out of 2 items documented1 out of 1 items with examples
  • Size
  • Source code size: 25.59 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.59 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 10s Average build duration of successful builds.
  • all releases: 10s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • Repository
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • Commander-lol

Web Instant

Provides Spot, a version of Instant that works both in environments that support Instant and wasm family targets. On desktop, the internal representation uses std::time::Instant. On the web, the internal representation is an f64, and uses js_sys::Date methods to cover functinality where required

All the methods on Instant are implemented for Spot, so you can just replace uses of std::time::Instant with web_instant::Spot

Install

cargo add web_instant

Usage

use web_instant::Spot;
use std::time::Duration;

fn my_cross_platform_timer(last_time: Spot) {
    let time_diff: Duration = Spot::now() - last_time;
    println!("It has been {} seconds", time_diff.as_secs());
}