Struct mozjs::jsapi::mozilla::TimeStamp

source ·
#[repr(C)]
pub struct TimeStamp { pub mValue: u64, }
Expand description

Instances of this class represent moments in time, or a special “null” moment. We do not use the non-monotonic system clock or local time, since they can be reset, causing apparent backward travel in time, which can confuse algorithms. Instead we measure elapsed time according to the system. This time can never go backwards (i.e. it never wraps around, at least not in less than five million years of system elapsed time). It might not advance while the system is sleeping. If TimeStamp::SetNow() is not called at all for hours or days, we might not notice the passage of some of that time.

We deliberately do not expose a way to convert TimeStamps to some particular unit. All you can do is compute a difference between two TimeStamps to get a TimeDuration. You can also add a TimeDuration to a TimeStamp to get a new TimeStamp. You can’t do something meaningless like add two TimeStamps.

Internally this is implemented as either a wrapper around

  • high-resolution, monotonic, system clocks if they exist on this platform
  • PRIntervalTime otherwise. We detect wraparounds of PRIntervalTime and work around them.

This class is similar to C++11’s time_point, however it is explicitly nullable and provides an IsNull() method. time_point is initialized to the clock’s epoch and provides a time_since_epoch() method that functions similiarly. i.e. t.IsNull() is equivalent to t.time_since_epoch() == decltype(t)::duration::zero();

Note that, since TimeStamp objects are small, prefer to pass them by value unless there is a specific reason not to do so.

Fields§

§mValue: u64

When built with PRIntervalTime, a value of 0 means this instance is “null”. Otherwise, the low 32 bits represent a PRIntervalTime, and the high 32 bits represent a counter of the number of rollovers of PRIntervalTime that we’ve seen. This counter starts at 1 to avoid a real time colliding with the “null” value.

PR_INTERVAL_MAX is set at 100,000 ticks per second. So the minimum time to wrap around is about 2^64/100000 seconds, i.e. about 5,849,424 years.

When using a system clock, a value is system dependent.

Trait Implementations§

source§

impl Clone for TimeStamp

source§

fn clone(&self) -> TimeStamp

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for TimeStamp

source§

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

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

impl PartialEq<TimeStamp> for TimeStamp

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Copy for TimeStamp

source§

impl StructuralPartialEq for TimeStamp

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. 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 Twhere 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 Twhere T: Clone,

§

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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.