Skip to main content

UnixNanos

Struct UnixNanos 

Source
pub struct UnixNanos(/* private fields */);
Expand description

Represents a timestamp in nanoseconds since the UNIX epoch.

Implementations§

Source§

impl UnixNanos

Source

pub const fn new(value: u64) -> Self

Creates a new UnixNanos instance.

Source

pub const fn max() -> Self

Creates a new UnixNanos instance with the maximum valid value.

Source

pub const fn is_zero(&self) -> bool

Returns true if the value of this instance is zero.

Source

pub const fn as_u64(&self) -> u64

Returns the underlying value as u64.

Source

pub const fn as_seconds(&self) -> u64

Returns the timestamp as seconds, truncating sub-second precision.

Source

pub const fn as_millis(&self) -> u64

Returns the timestamp as milliseconds, truncating sub-millisecond precision.

Source

pub const fn as_micros(&self) -> u64

Returns the timestamp as microseconds, truncating sub-microsecond precision.

Source

pub const fn from_seconds(seconds: u64) -> Self

Creates a new UnixNanos from a second timestamp.

§Panics

Panics if the result overflows u64.

Source

pub const fn from_millis(millis: u64) -> Self

Creates a new UnixNanos from a millisecond timestamp.

§Panics

Panics if the result overflows u64.

Source

pub const fn from_micros(micros: u64) -> Self

Creates a new UnixNanos from a microsecond timestamp.

§Panics

Panics if the result overflows u64.

Source

pub const fn as_i64(&self) -> i64

Returns the underlying value as i64.

§Panics

Panics if the value exceeds i64::MAX (approximately year 2262).

Source

pub const fn as_f64(&self) -> f64

Returns the underlying value as f64.

Source

pub const fn to_datetime_utc(&self) -> DateTime<Utc>

Converts the underlying value to a datetime (UTC).

§Panics

Panics if the value exceeds i64::MAX (approximately year 2262).

Source

pub fn to_rfc3339(&self) -> String

Converts the underlying value to an ISO 8601 (RFC 3339) string.

Source

pub const fn duration_since(&self, other: &Self) -> Option<DurationNanos>

Calculates the duration in nanoseconds since another UnixNanos instance.

Returns Some(duration) if self is later than other, otherwise None if other is greater than self (indicating a negative duration is not possible with DurationNanos).

Source

pub fn checked_add<T: Into<u64>>(self, rhs: T) -> Option<Self>

Returns Some(self + rhs) or None if the addition would overflow

Source

pub fn checked_sub<T: Into<u64>>(self, rhs: T) -> Option<Self>

Returns Some(self - rhs) or None if the subtraction would underflow

Source

pub fn saturating_add_ns<T: Into<u64>>(self, rhs: T) -> Self

Saturating addition – if overflow occurs the value is clamped to u64::MAX.

Source

pub fn saturating_sub_ns<T: Into<u64>>(self, rhs: T) -> Self

Saturating subtraction – if underflow occurs the value is clamped to 0.

Methods from Deref<Target = u64>§

1.43.0 · Source

pub const MIN: u64 = 0

1.43.0 · Source

pub const MAX: u64

1.53.0 · Source

pub const BITS: u32

Trait Implementations§

Source§

impl Add for UnixNanos

Adds two UnixNanos values.

§Panics

Panics on overflow. This is intentional fail-fast behavior: overflow in timestamp arithmetic indicates a logic error in calculations that would corrupt data. Use UnixNanos::checked_add() or UnixNanos::saturating_add_ns() if you need explicit overflow handling.

Source§

type Output = UnixNanos

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Self) -> Self::Output

Performs the + operation. Read more
Source§

impl Add<u64> for UnixNanos

Adds a u64 nanosecond value to UnixNanos.

§Panics

Panics on overflow. This is intentional fail-fast behavior for timestamp arithmetic. Use UnixNanos::checked_add() for explicit overflow handling.

Source§

type Output = UnixNanos

The resulting type after applying the + operator.
Source§

fn add(self, rhs: u64) -> Self::Output

Performs the + operation. Read more
Source§

impl<T: Into<u64>> AddAssign<T> for UnixNanos

Add-assigns a value to UnixNanos.

§Panics

Panics on overflow. This is intentional fail-fast behavior for timestamp arithmetic.

Source§

fn add_assign(&mut self, other: T)

Performs the += operation. Read more
Source§

impl Clone for UnixNanos

Source§

fn clone(&self) -> UnixNanos

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 Copy for UnixNanos

Source§

impl Debug for UnixNanos

Source§

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

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

impl Default for UnixNanos

Source§

fn default() -> UnixNanos

Returns the “default value” for a type. Read more
Source§

impl Deref for UnixNanos

Source§

type Target = u64

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<'de> Deserialize<'de> for UnixNanos

Source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for UnixNanos

Source§

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

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

impl Eq for UnixNanos

Source§

impl From<&str> for UnixNanos

Converts a string slice to UnixNanos.

§Panics

This implementation will panic if the string cannot be parsed into a valid UnixNanos. This is intentional fail-fast behavior where invalid timestamps indicate a critical logic error that should halt execution rather than silently propagate incorrect data.

For error handling without panicking, use str::parse::<UnixNanos>() which returns a Result.

Source§

fn from(value: &str) -> Self

Converts to this type from the input type.
Source§

impl From<DateTime<Utc>> for UnixNanos

Source§

fn from(value: DateTime<Utc>) -> Self

Converts to this type from the input type.
Source§

impl From<String> for UnixNanos

Converts a String to UnixNanos.

§Panics

This implementation will panic if the string cannot be parsed into a valid UnixNanos. This is intentional fail-fast behavior where invalid timestamps indicate a critical logic error that should halt execution rather than silently propagate incorrect data.

For error handling without panicking, use str::parse::<UnixNanos>() which returns a Result.

Source§

fn from(value: String) -> Self

Converts to this type from the input type.
Source§

impl From<SystemTime> for UnixNanos

Source§

fn from(value: SystemTime) -> Self

Converts to this type from the input type.
Source§

impl From<UnixNanos> for u64

Source§

fn from(value: UnixNanos) -> Self

Converts to this type from the input type.
Source§

impl From<UnixNanos> for DateTime<Utc>

Source§

fn from(value: UnixNanos) -> Self

Converts to this type from the input type.
Source§

impl From<u64> for UnixNanos

Source§

fn from(value: u64) -> Self

Converts to this type from the input type.
Source§

impl FromStr for UnixNanos

Source§

type Err = Box<dyn Error>

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
Source§

impl Hash for UnixNanos

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 Ord for UnixNanos

Source§

fn cmp(&self, other: &UnixNanos) -> 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 PartialEq for UnixNanos

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq<Option<u64>> for UnixNanos

Source§

fn eq(&self, other: &Option<u64>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq<UnixNanos> for u64

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq<u64> for UnixNanos

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for UnixNanos

Source§

fn partial_cmp(&self, other: &UnixNanos) -> 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 PartialOrd<Option<u64>> for UnixNanos

Source§

fn partial_cmp(&self, other: &Option<u64>) -> 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 PartialOrd<UnixNanos> for u64

Source§

fn partial_cmp(&self, other: &UnixNanos) -> 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 PartialOrd<u64> for UnixNanos

Source§

fn partial_cmp(&self, other: &u64) -> 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 Serialize for UnixNanos

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for UnixNanos

Source§

impl Sub for UnixNanos

Subtracts one UnixNanos from another.

§Panics

Panics on underflow. This is intentional fail-fast behavior: underflow in timestamp arithmetic indicates a logic error in calculations that would corrupt data. Use UnixNanos::checked_sub() or UnixNanos::saturating_sub_ns() if you need explicit underflow handling.

Source§

type Output = UnixNanos

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Self) -> Self::Output

Performs the - operation. Read more
Source§

impl Sub<u64> for UnixNanos

Subtracts a u64 nanosecond value from UnixNanos.

§Panics

Panics on underflow. This is intentional fail-fast behavior for timestamp arithmetic. Use UnixNanos::checked_sub() for explicit underflow handling.

Source§

type Output = UnixNanos

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: u64) -> Self::Output

Performs the - operation. Read more
Source§

impl<T: Into<u64>> SubAssign<T> for UnixNanos

Sub-assigns a value from UnixNanos.

§Panics

Panics on underflow. This is intentional fail-fast behavior for timestamp arithmetic.

Source§

fn sub_assign(&mut self, other: T)

Performs the -= operation. Read more

Auto Trait Implementations§

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
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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
§

impl<Q, K> Comparable<K> for Q
where Q: Ord + ?Sized, K: Borrow<Q> + ?Sized,

§

fn compare(&self, key: &K) -> Ordering

Compare self to key and return their ordering.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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.

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
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 = 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.
§

impl<T> Ungil for T
where T: Send,