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_millis(millis: i64) -> Self
pub const fn from_millis(millis: i64) -> Self
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) -> i128
pub const fn as_nanos(&self) -> i128
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 for Time
impl AddAssign for Time
source§fn add_assign(&mut self, rhs: Self)
fn add_assign(&mut self, rhs: Self)
Performs the
+=
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>,
Deserialize this value from the given Serde deserializer. Read more
source§impl Ord for Time
impl Ord for Time
source§impl PartialOrd for Time
impl PartialOrd for Time
source§impl SubAssign for Time
impl SubAssign for Time
source§fn sub_assign(&mut self, rhs: Self)
fn sub_assign(&mut self, rhs: Self)
Performs the
-=
operation. Read moreimpl Copy for Time
impl Eq for Time
impl StructuralPartialEq for Time
Auto Trait Implementations§
impl Freeze for Time
impl RefUnwindSafe for Time
impl Send for Time
impl Sync for Time
impl Unpin for Time
impl UnwindSafe for Time
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
Mutably borrows from an owned value. Read more
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)source§impl<T> CloneToUninit for Twhere
T: Copy,
impl<T> CloneToUninit for Twhere
T: Copy,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)§impl<'de, T> DynamicDeserialize<'de> for Twhere
T: Type + Deserialize<'de> + ?Sized,
impl<'de, T> DynamicDeserialize<'de> for Twhere
T: Type + Deserialize<'de> + ?Sized,
§type Deserializer = PhantomData<T>
type Deserializer = PhantomData<T>
A DeserializeSeed implementation for this type.
§impl<T> DynamicType for Twhere
T: Type + ?Sized,
impl<T> DynamicType for Twhere
T: Type + ?Sized,
§fn dynamic_signature(&self) -> Signature<'_>
fn dynamic_signature(&self) -> Signature<'_>
Get the signature for the implementing type. Read more
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
§impl<T> NoneValue for Twhere
T: Default,
impl<T> NoneValue for Twhere
T: Default,
type NoneType = T
§fn null_value() -> T
fn null_value() -> T
The none-equivalent value.