Skip to main content

PublishTime

Struct PublishTime 

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

A release publish instant, normalized to Unix epoch seconds (UTC).

Copy and cheap to pass around, so it fits into Box<dyn Version> trait objects without lifetime or allocation concerns.

§Examples

use deps_core::PublishTime;

let published = PublishTime::parse_rfc3339("2026-07-18T23:05:13Z").unwrap();
let now = PublishTime::from_unix_secs(published.as_unix_secs() + 3600);

assert_eq!(published.age_secs_from(now), 3600);

Implementations§

Source§

impl PublishTime

Source

pub fn now() -> Self

Returns the current time as a PublishTime.

Uses std::time::SystemTime rather than the time crate’s own “now” APIs, so this module never needs the local-offset/ wasm-bindgen features. A clock before the Unix epoch saturates to 0.

§Examples
use deps_core::PublishTime;

let now = PublishTime::now();
assert!(now.as_unix_secs() > 0);
Source

pub const fn from_unix_secs(secs: i64) -> Self

Builds a PublishTime directly from Unix epoch seconds.

§Examples
use deps_core::PublishTime;

let t = PublishTime::from_unix_secs(1_753_052_713);
assert_eq!(t.as_unix_secs(), 1_753_052_713);
Source

pub fn parse_rfc3339(s: &str) -> Option<Self>

Parses an RFC 3339 timestamp string into a PublishTime.

Accepts every shape seen across v1 registries: a bare Z suffix, arbitrary fractional-second digits, and a numeric UTC offset (+00:00). Returns None on any parse failure — per US-003, a missing or malformed timestamp degrades to pre-feature behavior rather than surfacing an error.

§Examples
use deps_core::PublishTime;

assert!(PublishTime::parse_rfc3339("2026-07-18T23:05:13Z").is_some());
assert!(PublishTime::parse_rfc3339("2026-05-14T19:25:27.735762Z").is_some());
assert!(PublishTime::parse_rfc3339("2026-01-02T08:56:05+00:00").is_some());
assert!(PublishTime::parse_rfc3339("not a timestamp").is_none());
assert!(PublishTime::parse_rfc3339("").is_none());
Source

pub const fn as_unix_secs(self) -> i64

Returns this instant as Unix epoch seconds.

§Examples
use deps_core::PublishTime;

let t = PublishTime::from_unix_secs(42);
assert_eq!(t.as_unix_secs(), 42);
Source

pub const fn age_secs_from(self, now: Self) -> u64

Age of this publish instant relative to now, in seconds.

A self in the future relative to now (clock skew, or a registry timestamp bug) saturates to age 0 rather than underflowing or returning a negative duration — chosen because a slightly-ahead registry clock is exactly the “just published” case the freshness signal exists to surface, so clamping preserves the signal instead of silently losing it.

§Examples
use deps_core::PublishTime;

let published = PublishTime::from_unix_secs(1_000);
let now = PublishTime::from_unix_secs(1_100);
assert_eq!(published.age_secs_from(now), 100);

// Clock skew: published "after" now clamps to 0, not a negative age.
let future = PublishTime::from_unix_secs(2_000);
assert_eq!(future.age_secs_from(now), 0);

Trait Implementations§

Source§

impl Clone for PublishTime

Source§

fn clone(&self) -> PublishTime

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 PublishTime

Source§

impl Debug for PublishTime

Source§

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

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

impl Eq for PublishTime

Source§

impl Ord for PublishTime

Source§

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

Source§

fn eq(&self, other: &PublishTime) -> 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 PublishTime

Source§

fn partial_cmp(&self, other: &PublishTime) -> 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 StructuralPartialEq for PublishTime

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

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

§

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

Checks if this value is equivalent to the given key. Read more
§

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

§

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

Checks if this value is equivalent to the given key. Read more
§

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.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> PolicyExt for T
where T: ?Sized,

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
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.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more