Crate fugit

Source
Expand description

fugit provides a comprehensive library of Duration and Instant for the handling of time in embedded systems. The library is specifically designed to maximize const-ification which allows for most comparisons and changes of time-base to be made at compile time, rather than run time.

The library is aimed at ease-of-use and performance first.

use fugit::{Duration, ExtU32};

// Efficient short-hands (`.millis()`, ...)
let d = Duration::<u32, 1, 1_000>::from_ticks(111);

let sum1 = d + 300.millis();
//             ^^^ Compile time move of base, only a sum is needed and no change of base


// -----------------------

// Best effort for fixed types
fn bar(d1: Duration<u32, 1, 1_000>, d2: Duration<u32, 1, 1_000_000>) {
    let sum = d1 + d2.convert();
    //        ^^^^^^^ Run time move of base, will use a `mul` and `div` instruction (Cortex-M3+) to
    //                perform the move of base.
    //                The `.convert()` explicitly signals the move of base.

    let ops = d1 > d2;
    //        ^^^^^^^ Run time comparison of different base, will use 2 `mul` instructions
    //                (Cortex-M3+) to perform the comparison.
}

fn baz(d1: Duration<u64, 1, 1_000>, d2: Duration<u64, 1, 1_000_000>) {
    let sum = d1 + d2.convert();
    //        ^^^^^^^ Run time move of base, will use a `mul` insruction and `div`
    //                soft-impl (Cortex-M3+) to perform the move of base.
    //                The `.convert()` explicitly signals the move of base.

    let ops = d1 > d2;
    //        ^^^^^^^ Run time comparison of different base, will use 4 `mul` instructions
    //                (Cortex-M3+) to perform the comparison.
}

Structs§

Duration
Represents a duration of time.
Instant
Represents an instant in time.
Rate
Represents a frequency.

Traits§

ExtU32
Extension trait for simple short-hands for u32 Durations
ExtU64
Extension trait for simple short-hands for u64 Durations
ExtU32Ceil
Extension trait for simple short-hands for u32 Durations (ceil rounded)
ExtU64Ceil
Extension trait for simple short-hands for u64 Durations (ceil rounded)
RateExtU32
Extension trait for simple short-hands for u32 Rate
RateExtU64
Extension trait for simple short-hands for u64 Rate

Type Aliases§

Hertz
Alias for hertz rate
HertzU32
Alias for hertz rate (u32 backing storage)
HertzU64
Alias for hertz rate (u64 backing storage)
HoursDuration
Alias for hours duration
HoursDurationU32
Alias for hours duration (u32 backing storage)
HoursDurationU64
Alias for hours duration (u64 backing storage)
Kilohertz
Alias for kilohertz rate
KilohertzU32
Alias for kilohertz rate (u32 backing storage)
KilohertzU64
Alias for kilohertz rate (u64 backing storage)
Megahertz
Alias for megahertz rate
MegahertzU32
Alias for megahertz rate (u32 backing storage)
MegahertzU64
Alias for megahertz rate (u64 backing storage)
MicrosDuration
Alias for microsecond duration
MicrosDurationU32
Alias for microsecond duration (u32 backing storage)
MicrosDurationU64
Alias for microsecond duration (u64 backing storage)
MillisDuration
Alias for millisecond duration
MillisDurationU32
Alias for millisecond duration (u32 backing storage)
MillisDurationU64
Alias for millisecond duration (u64 backing storage)
MinutesDuration
Alias for minutes duration
MinutesDurationU32
Alias for minutes duration (u32 backing storage)
MinutesDurationU64
Alias for minutes duration (u64 backing storage)
NanosDuration
Alias for nanosecond duration
NanosDurationU32
Alias for nanosecond duration (u32 backing storage)
NanosDurationU64
Alias for nanosecond duration (u64 backing storage)
SecsDuration
Alias for second duration
SecsDurationU32
Alias for second duration (u32 backing storage)
SecsDurationU64
Alias for second duration (u64 backing storage)
TimerDuration
Alias for durations that come from timers with a specific frequency
TimerDurationU32
Alias for durations that come from timers with a specific frequency (u32 backing storage)
TimerDurationU64
Alias for durations that come from timers with a specific frequency (u64 backing storage)
TimerInstant
Alias for instants that come from timers with a specific frequency
TimerInstantU32
Alias for instants that come from timers with a specific frequency (u32 backing storage)
TimerInstantU64
Alias for instants that come from timers with a specific frequency (u64 backing storage)
TimerRate
Alias for rate that come from timers with a specific frequency
TimerRateU32
Alias for rate that come from timers with a specific frequency (u32 backing storage)
TimerRateU64
Alias for rate that come from timers with a specific frequency (u64 backing storage)