pub struct Duration(/* private fields */);Expand description
A signed time interval measured in nanoseconds.
Duration is domain-agnostic: it represents the difference between two
instants and can be added to or subtracted from any crate::Time<S>.
§Range
i64 nanoseconds ==> approximately ±292 years.
§Examples
use gnss_time::Duration;
let one_sec = Duration::from_seconds(1);
let half_sec = Duration::from_millis(500);
assert_eq!(one_sec - half_sec, half_sec);
let neg = -one_sec;
assert_eq!(neg.as_nanos(), -1_000_000_000);Implementations§
Source§impl Duration
impl Duration
Sourcepub const ONE_NANOSECOND: Duration
pub const ONE_NANOSECOND: Duration
One nanosecond.
Sourcepub const ONE_SECOND: Duration
pub const ONE_SECOND: Duration
One second expressed as a Duration.
Sourcepub const fn from_nanos(nanos: i64) -> Self
pub const fn from_nanos(nanos: i64) -> Self
Create from a raw nanosecond count. Prefer the types constructors below.
Sourcepub const fn from_micros(micros: i64) -> Self
pub const fn from_micros(micros: i64) -> Self
Create from whole microseconds.
Sourcepub const fn from_millis(millis: i64) -> Self
pub const fn from_millis(millis: i64) -> Self
Create from whole milliseconds.
Sourcepub const fn from_seconds(secs: i64) -> Self
pub const fn from_seconds(secs: i64) -> Self
Create from whole seconds.
Sourcepub const fn from_minutes(mins: i64) -> Self
pub const fn from_minutes(mins: i64) -> Self
Create from whole minutes.
Sourcepub const fn from_hours(hours: i64) -> Self
pub const fn from_hours(hours: i64) -> Self
Create from whole hours.
Sourcepub const fn checked_from_micros(micros: i64) -> Option<Self>
pub const fn checked_from_micros(micros: i64) -> Option<Self>
Create from microseconds, returning None on overflow.
Sourcepub const fn checked_from_millis(millis: i64) -> Option<Self>
pub const fn checked_from_millis(millis: i64) -> Option<Self>
Create from milliseconds, returning None on overflow.
Sourcepub const fn checked_from_seconds(secs: i64) -> Option<Self>
pub const fn checked_from_seconds(secs: i64) -> Option<Self>
Create from whole seconds, returning None on overflow.
Source§impl Duration
impl Duration
Sourcepub const fn as_seconds(self) -> i64
pub const fn as_seconds(self) -> i64
Whole seconds (truncated toward zero).
Sourcepub fn as_seconds_f64(self) -> f64
pub fn as_seconds_f64(self) -> f64
Floating-point seconds. Precision is limited by f64 mantissa (~15
significant decimal digits), sufficient for sub-nanosecond accuracy up
to ~10 000 seconds.
Sourcepub const fn is_positive(self) -> bool
pub const fn is_positive(self) -> bool
Returns true if the duration is positive (> 0).
Sourcepub const fn is_negative(self) -> bool
pub const fn is_negative(self) -> bool
Returns true if the duration is negative (< 0).
Source§impl Duration
impl Duration
Sourcepub const fn checked_add(self, rhs: Duration) -> Option<Duration>
pub const fn checked_add(self, rhs: Duration) -> Option<Duration>
Add, returning None on overflow.
Sourcepub const fn checked_sub(self, rhs: Duration) -> Option<Duration>
pub const fn checked_sub(self, rhs: Duration) -> Option<Duration>
Subtract, returning None on overflow.
Sourcepub const fn saturating_add(self, rhs: Duration) -> Duration
pub const fn saturating_add(self, rhs: Duration) -> Duration
Add, saturating at i64::MAX / i64::MIN.
Sourcepub const fn saturating_sub(self, rhs: Duration) -> Duration
pub const fn saturating_sub(self, rhs: Duration) -> Duration
Subtract, saturating at i64::MAX / i64::MIN.
Sourcepub fn try_add(self, rhs: Duration) -> Result<Duration, GnssTimeError>
pub fn try_add(self, rhs: Duration) -> Result<Duration, GnssTimeError>
Fallible addition - returns GnssTimeError::Overflow on overflow.
Sourcepub fn try_sub(self, rhs: Duration) -> Result<Duration, GnssTimeError>
pub fn try_sub(self, rhs: Duration) -> Result<Duration, GnssTimeError>
Fallible subtraction — returns GnssTimeError::Overflow on overflow.
Trait Implementations§
Source§impl<S: TimeScale> AddAssign<Duration> for Time<S>
impl<S: TimeScale> AddAssign<Duration> for Time<S>
Source§fn add_assign(&mut self, rhs: Duration)
fn add_assign(&mut self, rhs: Duration)
+= operation. Read moreSource§impl AddAssign for Duration
impl AddAssign for Duration
Source§fn add_assign(&mut self, rhs: Self)
fn add_assign(&mut self, rhs: Self)
+= operation. Read moreSource§impl Ord for Duration
impl Ord for Duration
Source§impl PartialOrd for Duration
impl PartialOrd for Duration
Source§impl<S: TimeScale> SubAssign<Duration> for Time<S>
impl<S: TimeScale> SubAssign<Duration> for Time<S>
Source§fn sub_assign(&mut self, rhs: Duration)
fn sub_assign(&mut self, rhs: Duration)
-= operation. Read moreSource§impl SubAssign for Duration
impl SubAssign for Duration
Source§fn sub_assign(&mut self, rhs: Self)
fn sub_assign(&mut self, rhs: Self)
-= operation. Read more