Move `Instant` into core?

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

  1. 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 through tick), whether the specified time interval has been exceeded (Duration::from_secs(5)), all these calculations can actually be done with Instant::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.
  2. 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 as Instant(0)+Duration(5) = Instant(5), just Instant::now(), as a function that requires system support, needs to be supported by std

I don't understand how you can use Instant without Instant::now. That's the only way to construct an Instant. You seem to mention other methods like Instant::zero (and maybe Instant::tick?), but you don't define their semantics or show an example of their use. I'd suggest focusing more on those first, with "more to core" as a longer term goal.

14 Likes

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.