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_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<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 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<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 moreSource§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>,
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
.
§Examples
use nautilus_core::UnixNanos;
let nanos = UnixNanos::from("1234567890");
assert_eq!(nanos.as_u64(), 1234567890);
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 Ord for UnixNanos
impl Ord 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
Source§impl PartialOrd for UnixNanos
impl PartialOrd for UnixNanos
Source§impl Sub<u64> for UnixNanos
Subtracts a u64
nanosecond value from UnixNanos
.
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§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.
Source§impl<T: Into<u64>> SubAssign<T> for UnixNanos
Sub-assigns a value from UnixNanos
.
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)
fn sub_assign(&mut self, other: T)
-=
operation. Read moreimpl Copy for UnixNanos
impl Eq for UnixNanos
impl StructuralPartialEq for UnixNanos
Auto Trait Implementations§
impl Freeze for UnixNanos
impl RefUnwindSafe for UnixNanos
impl Send for UnixNanos
impl Sync for UnixNanos
impl Unpin 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
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<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.§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
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more