Skip to main content

Instant

Struct Instant 

Source
pub struct Instant<S: TimeScale> { /* private fields */ }
Expand description

Instant on one time scale, nanosecond resolution.

Comparison and subtraction only within one scale (see the module docs). Stored as seconds and nanoseconds since the scale’s 1970-01-01T00:00:00: range far beyond any calendar, and any i64 of Unix nanoseconds fits.

Implementations§

Source§

impl<S: TimeScale> Instant<S>

Source

pub const UNIX_EPOCH: Self

1970-01-01T00:00:00 on this scale.

Source

pub fn new(seconds: i64, nanos: u32) -> Result<Self>

Instant from whole seconds and nanoseconds within the second.

§Errors

KernelError::OutOfRange if nanos ≥ 1 s.

Source

pub const fn from_unix_seconds(seconds: i64) -> Self

Instant a whole number of seconds from the epoch.

Source

pub const fn from_unix_nanos(nanos: i64) -> Self

Instant nanos from the epoch (negative before it). Every i64 is representable.

Source

pub const fn seconds(self) -> i64

Whole seconds since the epoch, floored.

Source

pub const fn subsec_nanos(self) -> u32

Nanoseconds past the whole second, 0..1_000_000_000.

Source

pub const fn checked_unix_nanos(self) -> Option<i64>

Nanoseconds since the epoch, if within ~292 years (the i64 range).

Source

pub fn checked_add(self, duration: Duration) -> Option<Self>

self + duration; None on overflow.

Source

pub fn checked_sub(self, duration: Duration) -> Option<Self>

self − duration; None on underflow.

Source

pub fn saturating_add(self, duration: Duration) -> Self

self + duration, saturating.

Source

pub fn saturating_sub(self, duration: Duration) -> Self

self − duration, saturating.

Source

pub fn checked_duration_since(self, earlier: Self) -> Option<Duration>

Duration since earlier; None unless self ≥ earlier.

Source

pub fn duration_since(self, earlier: Self) -> Result<Duration>

Duration since earlier.

§Errors

KernelError::TimeReversed if earlier is later (clock stepped back or arguments swapped), with the amount.

Source

pub fn from_civil(civil: Civil) -> Result<Self>

Instant for a calendar reading on this scale.

§Errors

KernelError::OutOfRange for an invalid month, day, hour, minute, second or nanosecond. Second 60 (leap second) is rejected: the count has no place for it; the parser decides which side of the step it belongs to.

Source

pub fn civil(self) -> Civil

Calendar reading on this instant’s own scale.

Trait Implementations§

Source§

impl<S: Clone + TimeScale> Clone for Instant<S>

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<S: Copy + TimeScale> Copy for Instant<S>

Source§

impl<S: TimeScale> Debug for Instant<S>

Source§

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

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

impl<S: TimeScale> Display for Instant<S>

Source§

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

Formats as 2026-09-11T10:15:30.250 UTC (ISO 8601 plus scale). Precision: decimals of the second, default 3, max 9.

Source§

impl<S: Eq + TimeScale> Eq for Instant<S>

Source§

impl<S: Hash + TimeScale> Hash for Instant<S>

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<S: Ord + TimeScale> Ord for Instant<S>

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§

fn clamp_to<R>(self, range: R) -> Self
where Self: Sized, R: ClampBounds<Self>,

🔬This is a nightly-only experimental API. (clamp_to)
Restrict a value to a certain range. Read more
Source§

impl<S: PartialEq + TimeScale> PartialEq for Instant<S>

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<S: PartialOrd + TimeScale> PartialOrd for Instant<S>

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

impl<S: PartialEq + TimeScale> StructuralPartialEq for Instant<S>

Auto Trait Implementations§

§

impl<S> Freeze for Instant<S>
where PhantomData<S>: Freeze,

§

impl<S> RefUnwindSafe for Instant<S>

§

impl<S> Send for Instant<S>
where PhantomData<S>: Send,

§

impl<S> Sync for Instant<S>
where PhantomData<S>: Sync,

§

impl<S> Unpin for Instant<S>
where PhantomData<S>: Unpin,

§

impl<S> UnsafeUnpin for Instant<S>

§

impl<S> UnwindSafe for Instant<S>

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<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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.