4 个版本 (2 个破坏性更新)
| 0.3.0 | 2023 年 1 月 13 日 |
|---|---|
| 0.2.1 | 2023 年 1 月 4 日 |
| 0.2.0 | 2023 年 1 月 4 日 |
| 0.1.0 | 2023 年 1 月 4 日 |
3 在 #spot
每月 63 次下载
11KB
184 行
Web Instant
提供 Spot,这是一个同时支持 Instant 和 wasm 家族目标的版本。在桌面环境中,内部表示使用 std::time::Instant。在 Web 上,内部表示为 f64,并使用 js_sys::Date 方法来覆盖所需的功能
Instant 上的所有方法都已为 web_instant::Spot 实现,因此您只需用 web_instant::Spot 替换对 std::time::Instant 的使用即可
安装
cargo添加 web_instant
用法
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
提供 Spot,这是一个同时支持 Instant 和 wasm 家族目标的版本。在桌面环境中,内部表示使用 std::time::Instant。在 Web 上,内部表示为 f64,并使用 js_sys::Date 方法来覆盖所需的功能
Instant 上的所有方法都已为 web_instant::Spot 实现,因此您只需用 web_instant::Spot 替换对 std::time::Instant 的使用即可
安装
cargo添加 web_instant
用法
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());
}
依赖
~0–265KB