pub struct UnixNanos(/* private fields */);Expand description
Represents a timestamp in nanoseconds since the UNIX epoch.
Implementations§
Source§impl UnixNanos
impl UnixNanos
Sourcepub const fn as_seconds(&self) -> u64
pub const fn as_seconds(&self) -> u64
Returns the timestamp as seconds, truncating sub-second precision.
Sourcepub const fn as_millis(&self) -> u64
pub const fn as_millis(&self) -> u64
Returns the timestamp as milliseconds, truncating sub-millisecond precision.
Sourcepub const fn as_micros(&self) -> u64
pub const fn as_micros(&self) -> u64
Returns the timestamp as microseconds, truncating sub-microsecond precision.
Sourcepub const fn from_seconds(seconds: u64) -> Self
pub const fn from_seconds(seconds: u64) -> Self
Sourcepub const fn from_millis(millis: u64) -> Self
pub const fn from_millis(millis: u64) -> Self
Sourcepub const fn from_micros(micros: u64) -> Self
pub const fn from_micros(micros: u64) -> Self
Sourcepub const fn as_i64(&self) -> i64
pub const fn as_i64(&self) -> i64
Returns the underlying value as i64.
§Panics
Panics if the value exceeds i64::MAX (approximately year 2262).
Sourcepub const fn to_datetime_utc(&self) -> DateTime<Utc>
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).
Sourcepub fn to_rfc3339(&self) -> String
pub fn to_rfc3339(&self) -> String
Converts the underlying value to an ISO 8601 (RFC 3339) string.
Sourcepub const fn duration_since(&self, other: &Self) -> Option<DurationNanos>
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).
Sourcepub fn checked_add<T: Into<u64>>(self, rhs: T) -> Option<Self>
pub fn checked_add<T: Into<u64>>(self, rhs: T) -> Option<Self>
Returns Some(self + rhs) or None if the addition would overflow
Sourcepub fn checked_sub<T: Into<u64>>(self, rhs: T) -> Option<Self>
pub fn checked_sub<T: Into<u64>>(self, rhs: T) -> Option<Self>
Returns Some(self - rhs) or None if the subtraction would underflow
Sourcepub fn saturating_add_ns<T: Into<u64>>(self, rhs: T) -> Self
pub fn saturating_add_ns<T: Into<u64>>(self, rhs: T) -> Self
Saturating addition – if overflow occurs the value is clamped to u64::MAX.
Sourcepub fn saturating_sub_ns<T: Into<u64>>(self, rhs: T) -> Self
pub fn saturating_sub_ns<T: Into<u64>>(self, rhs: T) -> Self
Saturating subtraction – if underflow occurs the value is clamped to 0.
Trait Implementations§
Source§impl Add for UnixNanos
Adds two UnixNanos values.
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§impl Add<u64> for UnixNanos
Adds a u64 nanosecond value to UnixNanos.
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§impl<T: Into<u64>> AddAssign<T> for UnixNanos
Add-assigns a value to UnixNanos.
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)
fn add_assign(&mut self, other: T)
+= operation. Read moreimpl Copy for UnixNanos
Source§impl<'de> Deserialize<'de> for UnixNanos
impl<'de> Deserialize<'de> for UnixNanos
Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
impl Eq for UnixNanos
Source§impl From<&str> for UnixNanos
Converts a string slice to UnixNanos.
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§impl From<String> for UnixNanos
impl From<String> for 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§impl From<SystemTime> for UnixNanos
impl From<SystemTime> for UnixNanos
Source§fn from(value: SystemTime) -> Self
fn from(value: SystemTime) -> Self
Source§impl Ord for UnixNanos
impl Ord for UnixNanos
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialEq<Option<u64>> for UnixNanos
impl PartialEq<Option<u64>> for UnixNanos
Source§impl PartialOrd for UnixNanos
impl PartialOrd for UnixNanos
Source§impl PartialOrd<Option<u64>> for UnixNanos
impl PartialOrd<Option<u64>> for UnixNanos
Source§impl PartialOrd<UnixNanos> for u64
impl PartialOrd<UnixNanos> for u64
Source§impl PartialOrd<u64> for UnixNanos
impl PartialOrd<u64> for UnixNanos
impl StructuralPartialEq for UnixNanos
Source§impl Sub for UnixNanos
Subtracts one UnixNanos from another.
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.
Auto Trait Implementations§
impl Freeze for UnixNanos
impl RefUnwindSafe for UnixNanos
impl Send for UnixNanos
impl Sync for UnixNanos
impl Unpin for UnixNanos
impl UnsafeUnpin for UnixNanos
impl UnwindSafe for UnixNanos
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.