4 releases (2 breaking)

0.3.0 Jan 13, 2023
0.2.1 Jan 4, 2023
0.2.0 Jan 4, 2023
0.1.0 Jan 4, 2023

#3 in #spot

39 downloads per month

Apache-2.0

11KB
184 lines

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());
}

lib.rs:

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 functionality 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());
}

Dependencies

~0–270KB