Std.Measurements (Cure Standard Library v0.37.2)

View Source

Literal units of measure (design 2026-07-08-units-macro-design).

A number written immediately before a registered suffix expands, at parse time, into the matching constructor call — no runtime cost beyond the wrapped integer. The suffixes are globally active (like :syntax macros), so use Std.Measurements is only needed to bring the operations and the wrapper types into scope, not to enable the sugar.

500ms ==> Std.Measurements.ms(500) # a Duration of 500_000 microseconds 3khz ==> Std.Measurements.khz(3) # a Frequency of 3_000 hertz 80pct ==> Std.Measurements.pct(80) # a Percent 9600baud ==> Std.Measurements.baud(9600) # a Baud rate

Each quantity is a closed record over one Int, so arithmetic stays same-unit: add/sub/scale are defined per quantity and there is no cross-quantity operation, which is what makes 500ms and 3khz unmixable.

Examples

use Std.Measurements

let budget = add(500ms, 250ms)      # a Duration of 750_000 microseconds
as_ms(budget)                        # => 750

Summary

Types

A serial signalling rate, stored as symbols per second.

A length of time, stored as microseconds.

A rate, stored as hertz.

A percentage. The wrapper keeps percentages from being mixed with bare integers or other quantities; range enforcement (0..100) awaits the return of refinement/Bounded literals and is not checked here.

Functions

The Duration truncated to whole milliseconds.

The Duration truncated to whole seconds.

The Duration as a whole number of microseconds.

A Baud rate of n symbols per second.

A Frequency of n hertz.

A Frequency of n kilohertz.

A Duration of n milliseconds.

A Percent of n.

A Duration of n seconds.

A Duration scaled by an integer factor.

Difference of two Durations (a - b).

A Duration of n microseconds.

Types

struct Baud

 struct Baud
   ?

A serial signalling rate, stored as symbols per second.

struct Duration

 struct Duration
   ?

A length of time, stored as microseconds.

struct Frequency

 struct Frequency
   ?

A rate, stored as hertz.

struct Percent

 struct Percent
   ?

A percentage. The wrapper keeps percentages from being mixed with bare integers or other quantities; range enforcement (0..100) awaits the return of refinement/Bounded literals and is not checked here.

Functions

add(a: Duration, b: Duration) -> Duration

 fn add(a: Duration, b: Duration) -> Duration

Sum of two Durations.

as_ms(d: Duration) -> Int

 fn as_ms(d: Duration) -> Int

The Duration truncated to whole milliseconds.

as_s(d: Duration) -> Int

 fn as_s(d: Duration) -> Int

The Duration truncated to whole seconds.

as_us(d: Duration) -> Int

 fn as_us(d: Duration) -> Int

The Duration as a whole number of microseconds.

baud(n: Int) -> Baud

 fn baud(n: Int) -> Baud

A Baud rate of n symbols per second.

hz(n: Int) -> Frequency

 fn hz(n: Int) -> Frequency

A Frequency of n hertz.

khz(n: Int) -> Frequency

 fn khz(n: Int) -> Frequency

A Frequency of n kilohertz.

ms(n: Int) -> Duration

 fn ms(n: Int) -> Duration

A Duration of n milliseconds.

pct(n: Int) -> Percent

 fn pct(n: Int) -> Percent

A Percent of n.

s(n: Int) -> Duration

 fn s(n: Int) -> Duration

A Duration of n seconds.

scale(d: Duration, k: Int) -> Duration

 fn scale(d: Duration, k: Int) -> Duration

A Duration scaled by an integer factor.

sub(a: Duration, b: Duration) -> Duration

 fn sub(a: Duration, b: Duration) -> Duration

Difference of two Durations (a - b).

us(n: Int) -> Duration

 fn us(n: Int) -> Duration

A Duration of n microseconds.