pub struct Instant<P: Profile> { /* private fields */ }Expand description
A point in absolute time: an unsigned integer count of ticks since the datum, parameterised by profile at the type level (Rule P).
Cross-profile arithmetic and comparison do not compile. Instant<UC1> and
Instant<UC2> are distinct types with no coercion between them; conversion is
available only through Instant::rebase, which reports the constant shift.
Implementations§
Source§impl<P: Profile> Instant<P>
impl<P: Profile> Instant<P>
Sourcepub fn to_ucid(&self) -> Result<Ucid>
pub fn to_ucid(&self) -> Result<Ucid>
The instant’s UCID (§7.2). UCAL-E0031 above 2^256 (Rule I).
Not a unique identifier: see the module documentation and Rule I.
Sourcepub fn from_bytes_slice(bytes: &[u8]) -> Result<Self>
pub fn from_bytes_slice(bytes: &[u8]) -> Result<Self>
Decode the canonical binary form from a slice, checking the width.
UCAL-E0030 if the slice is not exactly 64 bytes. The array-typed
Instant::from_bytes makes that unrepresentable; this exists for the
boundary where a length arrives from outside the type system — a socket, a
column, a file — which is precisely where Rule B’s fixed width needs
enforcing rather than assuming.
Source§impl<P: Profile> Instant<P>
The datum, as a const, on the default backend only.
impl<P: Profile> Instant<P>
The datum, as a const, on the default backend only.
§13 specifies pub const ZERO: Self. That is achievable when Ticks is
const-constructible, which it is on the default backend and is not on
bigint (a heap value cannot be a const). Instant::zero is the portable
form and is available on both.
Source§impl<P: Profile> Instant<P>
impl<P: Profile> Instant<P>
Sourcepub fn zero() -> Self
pub fn zero() -> Self
Tick 0 — the datum. A stipulated reference point, conventionally identified with the FLRW t→0 limit; not a measurement and not an observed event (Rule Q, N17).
Sourcepub fn from_ticks(ticks: Ticks) -> Result<Self>
pub fn from_ticks(ticks: Ticks) -> Result<Self>
Construct from a tick count, rejecting values outside the profile domain.
Sourcepub fn tier_value(&self, tier: Tier) -> u16
pub fn tier_value(&self, tier: Tier) -> u16
The decimal group value at a tier, in 0..=3124.
Sourcepub fn groups(&self, from: Tier, to: Tier) -> Result<Vec<u16>>
pub fn groups(&self, from: Tier, to: Tier) -> Result<Vec<u16>>
Group values for tiers from down to to, most significant first.
Sourcepub fn floor_to(&self, tier: Tier) -> Self
pub fn floor_to(&self, tier: Tier) -> Self
Truncate toward the datum. Truncation is rounding (G3, Rule G).
Sourcepub fn ceil_to(&self, tier: Tier) -> Result<Self>
pub fn ceil_to(&self, tier: Tier) -> Result<Self>
Round away from the datum, failing on domain exit.
Sourcepub fn round_to(&self, tier: Tier, mode: Rounding) -> Result<Self>
pub fn round_to(&self, tier: Tier, mode: Rounding) -> Result<Self>
Round to a tier under an explicit mode (Rule R).
Sourcepub fn window_at(&self, precision: Precision) -> Result<Window<P>>
pub fn window_at(&self, precision: Precision) -> Result<Window<P>>
The closed interval a value stated at this precision denotes (Rule T).
For Precision::Tick this is the degenerate window [v, v]. For a tier
it is [floor, floor + 5^e - 1] — never a bare instant, which is what
keeps failure mode F2 closed.
Sourcepub fn since(&self, earlier: &Self) -> Result<Delta>
pub fn since(&self, earlier: &Self) -> Result<Delta>
Elapsed ticks since an earlier instant. UCAL-E0020 if earlier is later
than self — Rule Z admits no negative result.
Sourcepub fn between(&self, other: &Self) -> Signed
pub fn between(&self, other: &Self) -> Signed
The signed difference self - other. Always succeeds.
Sourcepub fn checked_add(&self, d: &Delta) -> Result<Self>
pub fn checked_add(&self, d: &Delta) -> Result<Self>
Advance by a magnitude, failing on domain exit (UCAL-E0021).
Sourcepub fn checked_sub(&self, d: &Delta) -> Result<Self>
pub fn checked_sub(&self, d: &Delta) -> Result<Self>
Retreat by a magnitude, failing before the datum (UCAL-E0020).
Sourcepub fn to_bytes(&self) -> [u8; 64]
pub fn to_bytes(&self) -> [u8; 64]
Canonical binary form: 64 bytes, big-endian, zero-padded (§7.1, Rule B).
Byte order is chronological order, so the encoding is directly usable as a database key. Identical on every backend, which is what makes the cross-backend differential test a conformance test (Rule W).
Sourcepub fn from_bytes(bytes: &[u8; 64]) -> Result<Self>
pub fn from_bytes(bytes: &[u8; 64]) -> Result<Self>
Inverse of Instant::to_bytes.
Sourcepub fn rebase<Q: Profile>(&self) -> Result<(Instant<Q>, Signed)>
pub fn rebase<Q: Profile>(&self) -> Result<(Instant<Q>, Signed)>
Reinterpret under another profile, reporting the constant tick shift (D-14, Rule P).
The shift is Q::origin_offset() - P::origin_offset(): both profiles date
from their own datum, so rebasing is a translation. Returns the new instant
and the shift that was applied, because a caller that does not see the
shift cannot audit the conversion.
Trait Implementations§
impl<P: Profile> Copy for Instant<P>
u512 only.impl<P: Profile> Eq for Instant<P>
Source§impl<P: Profile> Ord for Instant<P>
Rule M: for instants in one profile, exactly one of a < b, a = b, a > b
holds, and it is the chronological order. Rule P makes the “in one profile”
part a type-level guarantee rather than a runtime check.
impl<P: Profile> Ord for Instant<P>
Rule M: for instants in one profile, exactly one of a < b, a = b, a > b
holds, and it is the chronological order. Rule P makes the “in one profile”
part a type-level guarantee rather than a runtime check.