#duration #instant #const #time

no-std typus_fugit

typenum powered time library for the embedded ecosystem

4 releases

0.1.3 Dec 10, 2024
0.1.2 Dec 6, 2024
0.1.1 Dec 4, 2024
0.1.0 Dec 4, 2024

#100 in Date and time

Download history 326/week @ 2024-12-02 159/week @ 2024-12-09

485 downloads per month

MIT/Apache

150KB
3K SLoC

typus_fugit

Crates.io Docs.rs

typus_fugit provides a comprehensive library of Duration and Instant for the handling of time in embedded systems, using compile-time types to represent values.

This library began as a fork of fugit, which is, in turn, a heavily inspired of std::chrono's Duration from C++ which does all it can at compile time.

The decision to fork was due to the desire to replace const-generics values represented in the type system. This provides:

  • Specification of legal values within the type system
  • Evaluation of values within the type system
  • Erasure of machine representation of values until needed at execution time

Initial implementation uses typenum for type-level values and evaluation. There is an intent to migrate to type_eval when it's ready.

Should I use typus_fugit over fugit?

I cannot escape the fact that forking fugit fractures the ecosystem. Please do not use, or depend, on this crate, unless the topics of values at the type-level is of interest to you. This crate is, in significant part, motivated by assessing the reality of what a migration from const-generics to type-vals would look like.

Aims

  • Try to stay in sync with fugit
    • If users wish to switch between the two, the process should be low-friction and relatively reliable
    • If fugit decides to migrate to types instead of consts, the result should not look very different to typus_fugit
  • no_std library with goals of user-friendliness and performance first
    • Priority placed on type-level evaluation
    • When type-level evaluation isn't available, use const fn where the possible.
    • All timebase operations performed using type-level evaluation
  • Support for both u32 and u64 backing storage with efficient instruction lowering on MCUs
    • On Cortex-M3 and up: no soft-impls pulled in for both u32 and u64 except when changing base on u64
    • Comparisons on u32 and u64 do not use division, only changing base with all constants calculated at compile time
  • Selection of base happens at compile time, within the type-system.
    • A common problem is that run time changing of base robs us of a lot of optimization opportunities, but since types are used here, bases are evaluated at compile time.

Name

The original fugit name, as I understand it, comes from the latin phrase "tempus fugit", i.e. "time flies".

typus_fugit is a pun coming from said understanding.

Dependencies

~225–465KB
~11K SLoC