27 个稳定版本 (3 个主要版本)
| 3.3.1 | 2023年12月18日 |
|---|---|
| 3.3.0 | 2023年6月4日 |
| 3.2.4 | 2023年4月14日 |
| 3.2.0 | 2023年3月20日 |
| 0.2.0 | 2022年8月8日 |
#51 在 日期和时间
12,012 每月下载量
在 ncount 中使用
72KB
1K SLoC
libsw
libsw 是一个全面且安全的计时器实现。
Rust 的最低支持版本为 1.61.0。
许可证
双许可 MIT 或 Apache 2.0 许可证。
lib.rs:
libsw 是一个综合计时器实现。
它提供检查停止和算术,对操作何时发生有精确控制,并支持任意时间记录类型。
如果您想进行基准测试,请使用类似Criterion的工具。
简介
libsw 提供了StopwatchImpl类型作为计时器。
由于是泛型的,此实现不依赖于所使用的时间记录类型。任何实现了Instant特质(如StopwatchImpl<I>)的类型I都可以用于时间记录。
默认情况下,已为几种时间记录类型实现了Instant(见时间记录支持)。如果存在,这些实现将作为类型别名公开。
功能
| 名称 | 启用功能 | 描述 |
|---|---|---|
默认 |
std_instant,std_systemtime |
默认启用。 |
std |
依赖于标准库。为Error实现了std::error::Error。 |
|
nightly |
实现 core::error::Error 用于 Error 如果 std 未启用。需要 nightly 编译器。 |
|
std_instant |
std |
为 std::time::Instant 实现 Instant。公开 Sw 类型别名。 |
std_systemtime |
std |
为 std::time::SystemTime 实现 Instant。公开 SystemSw 类型别名。 |
tokio |
std |
为 tokio::time::Instant 实现 Instant。公开 TokioSw 类型别名。 |
time |
std |
为 time::Instant 实现 Instant。公开 TimeSw 类型别名。将 MSRV 提升至 1.62.1。 |
coarsetime |
std |
为 coarsetime::Instant 实现 Instant。公开 CoarseSw 类型别名。 |
quanta |
std |
为 quanta::Instant 实现 Instant。公开 QuantaSw 类型别名。 |
时间维护支持
libsw 可与任何实现了 Instant 的时间维护类型一起使用,只要启用了相应的功能标志。
请参阅 Instant 的 文档 了解支持的类型列表。
no_std 支持
默认情况下启用,但您可以通过禁用默认功能来禁用 std 功能标志。
在 Cargo.toml 中,
[dependencies]
# replace '...' with the appropriate version
libsw = { version = ..., default-features = false }
编译器支持
Rust 的最低支持版本为 1.61.0。
安全性
libsw 不包含不安全代码(#![forbid(unsafe_code)])。
依赖关系
~0–3MB
~54K SLoC