I think, in Instant, only now()
method is platform dependent, moving Instant
abstraction except now()
method into core
is not a difficult job (just need to The now method is not provided in the no_std environment), and this can play a great role in many no_std scenarios (such as embedded).
Why
- For example, I now want to implement a timer (for example, 5 seconds) in an embedded scenario. Then I actually just want to know, from the given timing zero point (
Instant::zero()
), the current time (get_time()
or calculated throughtick
), whether the specified time interval has been exceeded (Duration::from_secs(5)
), all these calculations can actually be done withInstant::now()
Separately, this allows us to calculate the Instant through multiple methods, whether it is calculated indirectly from the tick or directly obtains the current time through a system call. - Instant itself is just an abstract concept by design, which is why many platforms define Instant as
Instant(Duration)
in the standard library. I think Instant itself should be an abstract concept that appears in pairs with Duration, such asInstant(0)+Duration(5) = Instant(5)
, justInstant::now()
, as a function that requires system support, needs to be supported by std