Skip to main content

Crate t2t_core

Crate t2t_core 

Source
Expand description

Time values: points on the wall and monotonic clocks, counter readings, and the spans between them.

Each timeline has its own point, and each kind of count its own span. A point minus a point is a span, a point plus a span is a point, and points of two timelines never mix:

PointTimelineSpan
Timestampthe wall clock, from the Unix epochTimedelta
TaiTimestampInternational Atomic Time, from 1970 TAITimedelta
Uptimethe monotonic clock, from near bootTimedelta
RawUptimethe monotonic clock at the hardware’s rateTimedelta
BootUptimethe boot clock, suspensions countedTimedelta
Tickstampa hardware counter, from its own originTickdelta

Every point and span is an i64, and its operators saturate at the ends of the range rather than overflow, each with a checked_* twin. Every value has a spelling, which Display writes and FromStr reads back.

§Types

§Examples

use t2t_core::{Timed, Timedelta, Timestamp};

let stale: Timedelta = "1s".parse()?;
let captured = Timestamp::from_secs(1_700_000_000);
let sample = Timed::new(captured, 101_u64);

assert!(sample.elapsed(captured + Timedelta::from_millis(1_500)) > stale, "stale by now");

§Crate Features

None is on by default, and nothing reaches the operating system unless std is named; what std adds is on 64-bit Linux and macOS.

FeatureAdds
stdSystemTime conversions
serdeevery value’s spelling, and the serde modules for counts in a named unit
schemarsJsonSchema for every value with a spelling; turns serde on
zerocopythe zerocopy traits each type can honour, native-endian
chrono-04conversions to and from chrono 0.4’s DateTime and TimeDelta
jiff-02conversions to and from jiff 0.2’s Timestamp and SignedDuration
time-03conversions to and from time 0.3’s OffsetDateTime and Duration

Modules§

serdeserde
How a time crosses to a config file, a log or a peer.

Structs§

BootUptime
A point on the boot clock, in nanoseconds since boot, the machine’s suspensions counted.
OutOfRangeError
Why a time does not fit the type it was converted to: a negative span for a Duration, or a value past what a count of nanoseconds holds.
ParseTaiTimestampError
Why a string is not a TaiTimestamp.
ParseTickRateError
Why a string is not a TickRate.
ParseTickdeltaError
Why a string is not a Tickdelta, nor a Tickstamp.
ParseTimedeltaError
Why a string is not a Timedelta, nor a point counted from boot.
ParseTimestampError
Why a string is not a Timestamp.
RawUptime
A point on the monotonic clock at the hardware’s own rate, in nanoseconds since an origin near boot.
TaiTimestamp
A point on International Atomic Time, in nanoseconds since 1970-01-01T00:00:00 TAI.
TickRate
How many ticks a counter advances in a second: what turns Tickdelta into a Timedelta and back.
Tickdelta
A signed span of counter ticks: how far apart two Tickstamps are.
Tickstamp
A point on a hardware counter, in ticks since an origin the hardware chose.
Timed
A value T and the stamp S its writer captured it with.
Timedelta
A signed span of nanoseconds: how far apart two points on one timeline are.
Timestamp
A point on the wall clock, in nanoseconds since the Unix epoch.
Uptime
A point on the monotonic clock, in nanoseconds since an origin near boot.
UtcDateTime
A point on the wall clock read as a date and a time of day: UTC, in the proleptic Gregorian calendar.

Traits§

TimePoint
A point on one timeline, carried as a count of its unit since the timeline’s origin, with the span between two of them.