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

source

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);
source

pub const MIN: Self = _

The minimum time.

source

pub const MAX: Self = _

The maximum time.

source

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);
source

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);
source

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);
source

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);
source

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);
source

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);
source

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);
source

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);
source

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);
source

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);
source

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);
source

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));
source

pub const fn checked_add(self, other: Self) -> Option<Self>

Checked Time addition. Computes self + other, returning None if overflow occurred.

Examples
use mpris_server::Time;

assert_eq!(
    Time::from_micros(1).checked_add(Time::from_micros(1)),
    Some(Time::from_micros(2))
);
assert_eq!(Time::MAX.checked_add(Time::from_micros(1)), None);
source

pub const fn checked_sub(self, other: Self) -> Option<Self>

Checked Time subtraction. Computes self - other, returning None if overflow occurred.

Examples
use mpris_server::Time;

assert_eq!(
    Time::from_micros(2).checked_sub(Time::from_micros(1)),
    Some(Time::from_micros(1))
);
assert_eq!(Time::MIN.checked_sub(Time::from_micros(1)), None);
source

pub const fn saturating_add(self, other: Self) -> Self

Saturating Time addition. Computes self + other, returning Time::MAX if overflow occurred.

Examples
use mpris_server::Time;

assert_eq!(
    Time::from_micros(1).saturating_add(Time::from_micros(1)),
    Time::from_micros(2)
);
assert_eq!(Time::MAX.saturating_add(Time::from_micros(1)), Time::MAX);
source

pub const fn saturating_sub(self, other: Self) -> Self

Saturating Time subtraction. Computes self - other, returning Time::MIN if overflow occurred.

Examples
use mpris_server::Time;

assert_eq!(
    Time::from_micros(2).saturating_sub(Time::from_micros(1)),
    Time::from_micros(1)
);
assert_eq!(Time::MIN.saturating_sub(Time::from_micros(1)), Time::MIN);

Trait Implementations§

source§

impl Add<Time> for Time

§

type Output = Time

The resulting type after applying the + operator.
source§

fn add(self, other: Self) -> Self

Performs the + operation. Read more
source§

impl AddAssign<Time> for Time

source§

fn add_assign(&mut self, rhs: Self)

Performs the += operation. Read more
source§

impl Clone for Time

source§

fn clone(&self) -> Time

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 Time

source§

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

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

impl Default for Time

source§

fn default() -> Time

Returns the “default value” for a type. Read more
source§

impl<'de> Deserialize<'de> for Time

source§

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<'a> From<Time> for Value<'a>

source§

fn from(time: Time) -> Self

Converts to this type from the input type.
source§

impl Hash for Time

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl Ord for Time

source§

fn cmp(&self, other: &Time) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Selfwhere Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Selfwhere Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Selfwhere Self: Sized + PartialOrd<Self>,

Restrict a value to a certain interval. Read more
source§

impl PartialEq<Time> for Time

source§

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

source§

fn partial_cmp(&self, other: &Time) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

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

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

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

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

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

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

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

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl Serialize for Time

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl Sub<Time> for Time

§

type Output = Time

The resulting type after applying the - operator.
source§

fn sub(self, other: Self) -> Self

Performs the - operation. Read more
source§

impl SubAssign<Time> for Time

source§

fn sub_assign(&mut self, rhs: Self)

Performs the -= operation. Read more
source§

impl TryFrom<Value<'_>> for Time

§

type Error = Error

The type returned in the event of a conversion error.
source§

fn try_from(value: Value<'_>) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl Type for Time

source§

fn signature() -> Signature<'static>

Get the signature for the implementing type. Read more
source§

impl Copy for Time

source§

impl Eq for Time

source§

impl StructuralEq for Time

source§

impl StructuralPartialEq for Time

Auto Trait Implementations§

§

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

impl<'de, T> DynamicDeserialize<'de> for Twhere T: Type + Deserialize<'de> + ?Sized,

§

type Deserializer = PhantomData<T>

A DeserializeSeed implementation for this type.
§

fn deserializer_for_signature<S>( signature: S ) -> Result<<T as DynamicDeserialize<'de>>::Deserializer, Error>where S: TryInto<Signature<'de>>, <S as TryInto<Signature<'de>>>::Error: Into<Error>,

Get a deserializer compatible with this signature.
§

impl<T> DynamicType for Twhere T: Type + ?Sized,

§

fn dynamic_signature(&self) -> Signature<'_>

Get the signature for the implementing type. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

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

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

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

§

impl<T> NoneValue for Twhere T: Default,

§

type NoneType = T

§

fn null_value() -> T

The none-equivalent value.
source§

impl<T> Same<T> for T

§

type Output = T

Should always be Self
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.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

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

fn with_current_subscriber(self) -> WithDispatch<Self>

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

impl<T> DeserializeOwned for Twhere T: for<'de> Deserialize<'de>,