Struct mpris_server::Time
source · pub struct Time(/* private fields */);Expand description
A time with microsecond precision which can be negative.
Implementations§
source§impl Time
impl Time
sourcepub const ZERO: Self = _
pub const ZERO: Self = _
A time of zero.
Examples
use mpris_server::Time;
let time = Time::ZERO;
assert!(time.is_zero());
assert_eq!(time.as_micros(), 0);sourcepub const fn from_secs(secs: i64) -> Self
pub const fn from_secs(secs: i64) -> Self
Creates a new Time from the specified number of whole seconds.
Examples
use mpris_server::Time;
assert_eq!(Time::from_secs(5).as_nanos(), 5_000_000_000);sourcepub const fn from_millis(millis: i64) -> Self
pub const fn from_millis(millis: i64) -> Self
Creates a new Time from the specified number of whole milliseconds.
Examples
use mpris_server::Time;
assert_eq!(Time::from_millis(5).as_nanos(), 5_000_000);sourcepub const fn from_micros(micros: i64) -> Self
pub const fn from_micros(micros: i64) -> Self
Creates a new Time from the specified number of whole microseconds.
Examples
use mpris_server::Time;
assert_eq!(Time::from_micros(5).as_nanos(), 5_000);sourcepub const fn from_nanos(nanos: i64) -> Self
pub const fn from_nanos(nanos: i64) -> Self
Creates a new Time from the specified number of whole nanoseconds.
Note: This will round of the nanoseconds to microseconds level of precision.
Examples
use mpris_server::Time;
assert_eq!(Time::from_nanos(5).as_nanos(), 0);
assert_eq!(Time::from_nanos(5342).as_nanos(), 5000);sourcepub const fn as_secs(&self) -> i64
pub const fn as_secs(&self) -> i64
Returns the number of whole seconds contained by this Time.
Examples
use mpris_server::Time;
assert_eq!(Time::from_micros(5_000_000).as_secs(), 5);
assert_eq!(Time::from_micros(3).as_secs(), 0);sourcepub const fn as_millis(&self) -> i64
pub const fn as_millis(&self) -> i64
Returns the number of whole milliseconds contained by this Time.
Examples
use mpris_server::Time;
assert_eq!(Time::from_micros(5_000_000).as_millis(), 5_000);
assert_eq!(Time::from_micros(3).as_millis(), 0);sourcepub const fn as_micros(&self) -> i64
pub const fn as_micros(&self) -> i64
Returns the number of whole microseconds contained by this Time.
Examples
use mpris_server::Time;
assert_eq!(Time::from_micros(5_000_000).as_micros(), 5_000_000);
assert_eq!(Time::from_micros(3).as_micros(), 3);sourcepub const fn as_nanos(&self) -> i64
pub const fn as_nanos(&self) -> i64
Returns the number of whole nanoseconds contained by this Time.
Examples
use mpris_server::Time;
assert_eq!(Time::from_micros(5_000_000).as_nanos(), 5_000_000_000);
assert_eq!(Time::from_micros(3).as_nanos(), 3_000);sourcepub const fn is_zero(&self) -> bool
pub const fn is_zero(&self) -> bool
Returns true if this Time is zero.
Examples
use mpris_server::Time;
assert_eq!(Time::ZERO.is_zero(), true);
assert_eq!(Time::from_micros(1).is_zero(), false);sourcepub const fn is_negative(&self) -> bool
pub const fn is_negative(&self) -> bool
Returns true if this Time is negative.
Examples
use mpris_server::Time;
assert_eq!(Time::ZERO.is_negative(), false);
assert_eq!(Time::from_micros(-1).is_negative(), true);
assert_eq!(Time::from_micros(1).is_negative(), false);sourcepub const fn is_positive(&self) -> bool
pub const fn is_positive(&self) -> bool
Returns true if this Time is positive.
Examples
use mpris_server::Time;
assert_eq!(Time::ZERO.is_positive(), false);
assert_eq!(Time::from_micros(1).is_positive(), true);
assert_eq!(Time::from_micros(-1).is_positive(), false);sourcepub const fn abs(&self) -> Self
pub const fn abs(&self) -> Self
Returns the time as an absolute (non-negative) value.
Examples
use mpris_server::Time;
assert_eq!(Time::ZERO.abs(), Time::ZERO);
assert_eq!(Time::from_micros(-1).abs(), Time::from_micros(1));
assert_eq!(Time::from_micros(1).abs(), Time::from_micros(1));sourcepub const fn checked_add(self, other: Self) -> Option<Self>
pub const fn checked_add(self, other: Self) -> Option<Self>
sourcepub const fn checked_sub(self, other: Self) -> Option<Self>
pub const fn checked_sub(self, other: Self) -> Option<Self>
sourcepub const fn saturating_add(self, other: Self) -> Self
pub const fn saturating_add(self, other: Self) -> Self
sourcepub const fn saturating_sub(self, other: Self) -> Self
pub const fn saturating_sub(self, other: Self) -> Self
Trait Implementations§
source§impl AddAssign<Time> for Time
impl AddAssign<Time> for Time
source§fn add_assign(&mut self, rhs: Self)
fn add_assign(&mut self, rhs: Self)
+= operation. Read moresource§impl<'de> Deserialize<'de> for Time
impl<'de> Deserialize<'de> for Time
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 Ord for Time
impl Ord for Time
source§impl PartialEq<Time> for Time
impl PartialEq<Time> for Time
source§impl PartialOrd<Time> for Time
impl PartialOrd<Time> for Time
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self and other) and is used by the <=
operator. Read moresource§impl SubAssign<Time> for Time
impl SubAssign<Time> for Time
source§fn sub_assign(&mut self, rhs: Self)
fn sub_assign(&mut self, rhs: Self)
-= operation. Read more