状态
当前可运行:
| API | 返回值 | 说明 |
|---|---|---|
std.time.ms(value) | Duration | 构建毫秒级时长。 |
std.time.seconds(value) | Duration | 构建秒级时长。 |
std.time.add(a, b) | Duration | 将两个时长相加。 |
std.time.sub(a, b) | Duration | 从一个时长中减去另一个时长。 |
std.time.min(a, b) | Duration | 返回较小的时长。 |
std.time.max(a, b) | Duration | 返回较大的时长。 |
std.time.asMsFloor(value) | i32 | 转换为整数毫秒数。 |
std.time.lessThan(a, b) | Bool | 比较两个时长。 |
std.time.monotonic() | Duration | 在可用时读取目标单调时钟。 |
std.time.wallSeconds() | i64 | 在可用时读取目标挂钟秒数。 |
当前限制:
- 单调时钟时间点。
- 截止时间和请求预算。
- 目标特定的时钟可用性诊断。
元数据标签:
- effects: time
- allocation behavior: no allocation
- target support: 时长运算与目标无关;时钟读取需要支持 time 的目标
- error behavior: 不会失败的辅助函数
- ownership notes: 无所有权转移
- example:
examples/std-platform.0
示例
pub fn main Void world World ! let a std.time.ms 250 let b std.time.seconds 1 let total std.time.add a b if == (std.time.asMsFloor total) 1250 check world.out.write "duration ok\n"设计说明
当时间观测外部世界时,它是一种副作用。
纯时长运算可以保持零分配且与目标无关。