mirror of
https://github.com/embassy-rs/embassy.git
synced 2025-09-26 20:00:27 +00:00
time: add Instant::try_from_nanos
This commit is contained in:
parent
57f1517f70
commit
4d9563805c
@ -57,6 +57,17 @@ impl Instant {
|
||||
}
|
||||
}
|
||||
|
||||
/// Try to create an Instant from a nanosecond count since system boot.
|
||||
/// Fails if the number of nanoseconds is too large.
|
||||
pub const fn try_from_nanos(nanos: u64) -> Option<Self> {
|
||||
let Some(value) = nanos.checked_mul(TICK_HZ / GCD_1G) else {
|
||||
return None;
|
||||
};
|
||||
Some(Self {
|
||||
ticks: value / (1_000_000_000 / GCD_1G),
|
||||
})
|
||||
}
|
||||
|
||||
/// Try to create an Instant from a microsecond count since system boot.
|
||||
/// Fails if the number of microseconds is too large.
|
||||
pub const fn try_from_micros(micros: u64) -> Option<Self> {
|
||||
|
Loading…
x
Reference in New Issue
Block a user