Skip to main content

Instant

Struct Instant 

Source
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>

Source

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.

Source

pub fn from_ucid(u: &Ucid) -> Result<Self>

Recover an instant from its UCID.

Source

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.

§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

pub const ZERO: Self

Tick 0 — the datum (Rule Z, Rule Q).

Source§

impl<P: Profile> Instant<P>

Source

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).

Source

pub fn from_ticks(ticks: Ticks) -> Result<Self>

Construct from a tick count, rejecting values outside the profile domain.

Source

pub fn from_u64(v: u64) -> Result<Self>

Construct from a small tick count.

Source

pub fn ticks(&self) -> &Ticks

The raw tick count.

Source

pub fn tier_value(&self, tier: Tier) -> u16

The decimal group value at a tier, in 0..=3124.

Source

pub fn groups(&self, from: Tier, to: Tier) -> Result<Vec<u16>>

Group values for tiers from down to to, most significant first.

Source

pub fn floor_to(&self, tier: Tier) -> Self

Truncate toward the datum. Truncation is rounding (G3, Rule G).

Source

pub fn ceil_to(&self, tier: Tier) -> Result<Self>

Round away from the datum, failing on domain exit.

Source

pub fn round_to(&self, tier: Tier, mode: Rounding) -> Result<Self>

Round to a tier under an explicit mode (Rule R).

Source

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.

Source

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.

Source

pub fn between(&self, other: &Self) -> Signed

The signed difference self - other. Always succeeds.

Source

pub fn checked_add(&self, d: &Delta) -> Result<Self>

Advance by a magnitude, failing on domain exit (UCAL-E0021).

Source

pub fn checked_sub(&self, d: &Delta) -> Result<Self>

Retreat by a magnitude, failing before the datum (UCAL-E0020).

Source

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).

Source

pub fn from_bytes(bytes: &[u8; 64]) -> Result<Self>

Inverse of Instant::to_bytes.

Source

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§

Source§

impl<P: Profile> Clone for Instant<P>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<P: Profile> Copy for Instant<P>

Available on crate feature u512 only.
Source§

impl<P: Profile> Debug for Instant<P>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<P: Profile> Eq for Instant<P>

Source§

impl<P: Profile> Hash for Instant<P>

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
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.

Source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl<P: Profile> PartialEq for Instant<P>

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl<P: Profile> PartialOrd for Instant<P>

Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more

Auto Trait Implementations§

§

impl<P> Freeze for Instant<P>

§

impl<P> RefUnwindSafe for Instant<P>
where P: RefUnwindSafe,

§

impl<P> Send for Instant<P>
where P: Send,

§

impl<P> Sync for Instant<P>
where P: Sync,

§

impl<P> Unpin for Instant<P>
where P: Unpin,

§

impl<P> UnsafeUnpin for Instant<P>

§

impl<P> UnwindSafe for Instant<P>
where P: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<U> As for U

Source§

fn as_<T>(self) -> T
where T: CastFrom<U>, U: Sized,

Casts self to type T. The semantics of numeric casting with the as operator are followed, so <T as As>::as_::<U> can be used in the same way as T as U for numeric conversions. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.