Skip to content
Snippets Groups Projects
README.md 735 B
Newer Older
Louis's avatar
Louis committed
# Web Instant

Louis's avatar
Louis committed
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`,
Louis's avatar
Louis committed
and uses `js_sys::Date` methods to cover functinality where required

Louis's avatar
Louis committed
All the methods on `Instant` are implemented for `Spot`, so you can just replace uses of `std::time::Instant` with `web_instant::Spot`

Louis's avatar
Louis committed
## Install

`cargo add web_instant`

## Usage

Louis's avatar
Louis committed
```rust
Louis's avatar
Louis committed
use web_instant::Spot;
use std::time::Duration;

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