Struct libpulse_binding::time::MicroSeconds[][src]

pub struct MicroSeconds(pub u64);

Microseconds. Represents a span of time like std::time::Duration.

This is an unsigned 64-bit type, and thus represents absolute values only.

Implementations

impl MicroSeconds[src]

pub const INVALID: Self[src]

MicroSeconds value representing an ‘invalid’ time.

Examples

assert_eq!(MicroSeconds::INVALID, MicroSeconds(std::u64::MAX));

pub const SECOND: Self[src]

One second in microseconds.

Examples

assert_eq!(MicroSeconds::SECOND, MicroSeconds(1_000_000));

pub const MILLISECOND: Self[src]

One millisecond in microseconds.

Examples

assert_eq!(MicroSeconds::MILLISECOND, MicroSeconds(1_000));

pub const ZERO: Self[src]

Zero value.

Examples

assert_eq!(MicroSeconds::ZERO, MicroSeconds(0));

pub const MIN: Self[src]

Smallest valid time value (zero).

Examples

assert_eq!(MicroSeconds::MIN, MicroSeconds(0));

pub const MAX: Self[src]

Largest valid time value (largest integer value is reserved for representing ‘invalid’).

Roughly equal to 5,124,095,576 hours, 213,503,982 days, or 584,542 years.

Examples

assert_eq!(MicroSeconds::MAX, MicroSeconds(std::u64::MAX - 1));

pub const fn inner(&self) -> u64[src]

Get the inner u64 value.

Examples

assert_eq!(MicroSeconds(100).inner(), 100);

pub const fn is_valid(&self) -> bool[src]

Returns true so long as inner value is not Self::INVALID.

Examples

assert_eq!(MicroSeconds::MIN.is_valid(), true);
assert_eq!(MicroSeconds::MAX.is_valid(), true);
assert_eq!(MicroSeconds::INVALID.is_valid(), false);
assert_eq!(MicroSeconds::ZERO.is_valid(), true);
assert_eq!(MicroSeconds(60 * MICROS_PER_SEC).is_valid(), true);

pub const fn is_zero(&self) -> bool[src]

Returns true so long as inner value is zero.

Examples

assert_eq!(MicroSeconds::ZERO.is_zero(), true);
assert_eq!(MicroSeconds(0).is_zero(), true);
assert_eq!(MicroSeconds(1).is_zero(), false);

pub fn from_secs(secs: u64) -> Option<Self>[src]

Creates a new MicroSeconds from the specified number of whole seconds. Returns None on overflow.

Examples

assert_eq!(MicroSeconds::from_secs(2), Some(MicroSeconds(2_000_000)));
assert_eq!(MicroSeconds::from_secs(0xffff_ffff_0000_0000), None);

pub fn from_millis(millis: u64) -> Option<Self>[src]

Creates a new MicroSeconds from the specified number of whole milliseconds. Returns None on overflow.

Examples

assert_eq!(MicroSeconds::from_millis(23), Some(MicroSeconds(23_000)));
assert_eq!(MicroSeconds::from_millis(0xffff_ffff_0000_0000), None);

pub fn diff(self, other: Self) -> Self[src]

Returns the absolute difference with other.

Examples

assert_eq!(MicroSeconds(0).diff(MicroSeconds(0)), MicroSeconds(0));
assert_eq!(MicroSeconds(100).diff(MicroSeconds(100)), MicroSeconds(0));
assert_eq!(MicroSeconds(200).diff(MicroSeconds(150)), MicroSeconds(50));
assert_eq!(MicroSeconds(150).diff(MicroSeconds(200)), MicroSeconds(50));

pub const fn as_secs(&self) -> u64[src]

Returns the total number of whole seconds.

Examples

assert_eq!(MicroSeconds(2_300_000).as_secs(), 2);
assert_eq!(MicroSeconds(2_800_000).as_secs(), 2);

pub const fn as_millis(&self) -> u64[src]

Returns the total number of whole milliseconds.

Examples

assert_eq!(MicroSeconds(23_000_300).as_millis(), 23_000);
assert_eq!(MicroSeconds(23_000_800).as_millis(), 23_000);

pub fn from_secs_f64(secs: f64) -> Self[src]

Creates a new MicroSeconds from the specified number of seconds represented as f64.

Panics if secs is not finite, is negative, or the value overflows.

Examples

assert_eq!(MicroSeconds::from_secs_f64(0.5), MicroSeconds(500_000));
assert_eq!(MicroSeconds::from_secs_f64(2.3), MicroSeconds(2_300_000));

These should panic.

MicroSeconds::from_secs_f64(std::f64::INFINITY);
MicroSeconds::from_secs_f64(-0.5);
MicroSeconds::from_secs_f64(std::f64::MAX);
MicroSeconds::from_secs_f64(std::f64::NAN);

pub fn from_secs_f32(secs: f32) -> Self[src]

Creates a new MicroSeconds from the specified number of seconds represented as f32.

Panics if secs is not finite, is negative, or the value overflows.

Examples

assert_eq!(MicroSeconds::from_secs_f32(0.5), MicroSeconds(500_000));
assert_eq!(MicroSeconds::from_secs_f32(2.3), MicroSeconds(2_300_000));

These should panic.

MicroSeconds::from_secs_f32(std::f32::INFINITY);
MicroSeconds::from_secs_f32(-0.5);
MicroSeconds::from_secs_f32(std::f32::MAX);
MicroSeconds::from_secs_f32(std::f32::NAN);

pub fn as_secs_f64(&self) -> f64[src]

Returns the number of seconds as f64.

Examples

assert_eq!(MicroSeconds(2_300_000).as_secs_f64(), 2.3);
assert_eq!(MicroSeconds(500_000).as_secs_f64(), 0.5);

pub fn as_secs_f32(&self) -> f32[src]

Returns the number of seconds as f32.

Examples

assert_eq!(MicroSeconds(2_300_000).as_secs_f32(), 2.3);
assert_eq!(MicroSeconds(500_000).as_secs_f32(), 0.5);

pub fn checked_add(self, other: Self) -> Option<Self>[src]

Checked integer addition. Computes self + rhs, returning None if overflow occurred, using the inner integer’s checked_add() method.

Examples

let quater_minute = MicroSeconds(15 * MICROS_PER_SEC);
let half_minute = MicroSeconds(30 * MICROS_PER_SEC);
let three_quater_minute = MicroSeconds(45 * MICROS_PER_SEC);

assert_eq!(half_minute.checked_add(quater_minute), Some(three_quater_minute));
assert_eq!(MicroSeconds::MAX.checked_add(half_minute), None);

pub fn checked_add_duration(self, rhs: Duration) -> Option<Self>[src]

Checked integer addition. Computes self + rhs, returning None if overflow occurred, using the inner integer’s checked_add() method.

Examples

let half_minute = MicroSeconds(30 * MICROS_PER_SEC);
let duration1 = Duration::new(2, 5 * NANOS_PER_MICRO + 20); // 2s + 5us + 20ns
let duration2 = Duration::new(MicroSeconds::MAX.inner() / MICROS_PER_SEC, 0);

assert_eq!(half_minute.checked_add_duration(duration1), Some(MicroSeconds(32_000_005)));
assert_eq!(half_minute.checked_add_duration(duration2), None);

pub fn checked_sub(self, other: Self) -> Option<Self>[src]

Checked integer subtraction. Computes self - rhs, returning None if overflow occurred, using the inner integer’s checked_sub() method.

Examples

let quater_minute = MicroSeconds(15 * MICROS_PER_SEC);
let three_quater_minute = MicroSeconds(45 * MICROS_PER_SEC);
let whole_minute = MicroSeconds(60 * MICROS_PER_SEC);

assert_eq!(whole_minute.checked_sub(quater_minute), Some(three_quater_minute));
assert_eq!(quater_minute.checked_sub(whole_minute), None);

pub fn checked_sub_duration(self, rhs: Duration) -> Option<Self>[src]

Checked integer subtraction. Computes self - rhs, returning None if overflow occurred, using the inner integer’s checked_sub() method.

Examples

let half_minute = MicroSeconds(30 * MICROS_PER_SEC);
let duration1 = Duration::new(2, 5 * NANOS_PER_MICRO + 20); // 2s + 5us + 20ns
let duration2 = Duration::new(45, 0);

assert_eq!(half_minute.checked_sub_duration(duration1), Some(MicroSeconds(27_999_995)));
assert_eq!(half_minute.checked_sub_duration(duration2), None);

pub fn checked_mul(self, rhs: u32) -> Option<Self>[src]

Checked integer multiplication. Computes self * rhs, returning None if overflow occurred, using the inner integer’s checked_mul() method.

Examples

let quater_minute = MicroSeconds(15 * MICROS_PER_SEC);
let whole_minute = MicroSeconds(60 * MICROS_PER_SEC);

assert_eq!(quater_minute.checked_mul(4), Some(whole_minute));
assert_eq!(MicroSeconds::MAX.checked_mul(2), None);

pub fn checked_div(self, rhs: u32) -> Option<Self>[src]

Checked integer division. Computes self / rhs, returning None if rhs == 0, using the inner integer’s checked_div() method.

Examples

let quater_minute = MicroSeconds(15 * MICROS_PER_SEC);
let whole_minute = MicroSeconds(60 * MICROS_PER_SEC);

assert_eq!(whole_minute.checked_div(4), Some(quater_minute));
assert_eq!(whole_minute.checked_div(0), None);

pub fn checked_rem(self, rhs: u32) -> Option<Self>[src]

Checked integer remainder. Computes self % rhs, returning None if rhs == 0, using the inner integer’s checked_rem() method.

Examples

let quater_minute = MicroSeconds(15 * MICROS_PER_SEC);
let whole_minute = MicroSeconds(60 * MICROS_PER_SEC);

assert_eq!(whole_minute.checked_rem(4), Some(MicroSeconds::ZERO));
assert_eq!(whole_minute.checked_rem(7), Some(MicroSeconds(4)));
assert_eq!(whole_minute.checked_rem(0), None);

pub fn mul_f64(self, rhs: f64) -> Self[src]

Multiplies MicroSeconds by f64.

Converts to an f64 representing seconds, multiplies by the given factor, then converts back to microseconds.

Panics if rhs is not finite, is negative, or the value overflows.

Examples

let micros = MicroSeconds(2_700_000_000);

assert_eq!(micros.mul_f64(3.14), MicroSeconds(8_478_000_000));
assert_eq!(micros.mul_f64(3.14e5), MicroSeconds(847_800_000_000_000));

These should panic.

MicroSeconds::SECOND.mul_f64(std::f64::INFINITY);
MicroSeconds::SECOND.mul_f64(-0.5);
MicroSeconds(2 * MICROS_PER_SEC).mul_f64(std::f64::MAX / 10.0);
MicroSeconds::SECOND.mul_f64(std::f64::NAN);

pub fn mul_f32(self, rhs: f32) -> Self[src]

Multiplies MicroSeconds by f32.

Converts to an f32 representing seconds, multiplies by the given factor, then converts back to microseconds.

Panics if rhs is not finite, is negative, or the value overflows.

Examples

let micros = MicroSeconds(2_700_000_000);

// Note the rounding errors that are clear here.
assert_eq!(micros.mul_f32(3.14), MicroSeconds(8_478_000_152));
assert_eq!(micros.mul_f32(3.14e5), MicroSeconds(847_800_018_512_379));

These should panic.

MicroSeconds::SECOND.mul_f32(std::f32::INFINITY);
MicroSeconds::SECOND.mul_f32(-0.5);
MicroSeconds(2 * MICROS_PER_SEC).mul_f32(std::f32::MAX / 10.0);
MicroSeconds::SECOND.mul_f32(std::f32::NAN);

pub fn div_f64(self, rhs: f64) -> Self[src]

Divides MicroSeconds by f64.

Converts to an f64 representing seconds, divides by the given factor, then converts back to microseconds.

Panics if rhs is not finite, is negative, or the value overflows.

Examples

let micros = MicroSeconds(2_700_000_000);

assert_eq!(micros.div_f64(3.14), MicroSeconds(859_872_611));
assert_eq!(micros.div_f64(3.14e5), MicroSeconds(8_598));

These should panic.

MicroSeconds::SECOND.div_f64(-2.0);
MicroSeconds::MAX.div_f64(0.5);
MicroSeconds::SECOND.div_f64(std::f64::NAN);

pub fn div_f32(self, rhs: f32) -> Self[src]

Divides MicroSeconds by f32.

Converts to an f32 representing seconds, divides by the given factor, then converts back to microseconds.

Panics if rhs is not finite, is negative, or the value overflows.

Examples

let micros = MicroSeconds(2_700_000_000);

assert_eq!(micros.div_f32(3.14), MicroSeconds(859_872_559));
assert_eq!(micros.div_f32(3.14e5), MicroSeconds(8_598));

These should panic.

MicroSeconds::SECOND.div_f32(-2.0);
MicroSeconds::MAX.div_f32(0.5);
MicroSeconds::SECOND.div_f32(std::f32::NAN);

Trait Implementations

impl Add<Duration> for MicroSeconds[src]

type Output = Self

The resulting type after applying the + operator.

impl Add<MicroSeconds> for MicroSeconds[src]

type Output = Self

The resulting type after applying the + operator.

impl Add<MicroSeconds> for MonotonicTs[src]

type Output = Self

The resulting type after applying the + operator.

impl Add<MicroSeconds> for Timeval[src]

type Output = Self

The resulting type after applying the + operator.

impl Add<MicroSeconds> for UnixTs[src]

type Output = Self

The resulting type after applying the + operator.

impl AddAssign<Duration> for MicroSeconds[src]

impl AddAssign<MicroSeconds> for MicroSeconds[src]

impl AddAssign<MicroSeconds> for MonotonicTs[src]

impl AddAssign<MicroSeconds> for Timeval[src]

impl AddAssign<MicroSeconds> for UnixTs[src]

impl Clone for MicroSeconds[src]

impl Copy for MicroSeconds[src]

impl Debug for MicroSeconds[src]

impl Default for MicroSeconds[src]

impl Display for MicroSeconds[src]

impl Div<u32> for MicroSeconds[src]

type Output = Self

The resulting type after applying the / operator.

impl DivAssign<u32> for MicroSeconds[src]

impl Eq for MicroSeconds[src]

impl From<MicroSeconds> for Timeval[src]

impl From<Timeval> for MicroSeconds[src]

impl Mul<u32> for MicroSeconds[src]

type Output = Self

The resulting type after applying the * operator.

impl MulAssign<u32> for MicroSeconds[src]

impl Ord for MicroSeconds[src]

impl PartialEq<MicroSeconds> for MicroSeconds[src]

impl PartialOrd<MicroSeconds> for MicroSeconds[src]

impl Rem<u32> for MicroSeconds[src]

type Output = Self

The resulting type after applying the % operator.

impl RemAssign<u32> for MicroSeconds[src]

impl StructuralEq for MicroSeconds[src]

impl StructuralPartialEq for MicroSeconds[src]

impl Sub<Duration> for MicroSeconds[src]

type Output = Self

The resulting type after applying the - operator.

impl Sub<MicroSeconds> for MicroSeconds[src]

type Output = Self

The resulting type after applying the - operator.

impl Sub<MicroSeconds> for MonotonicTs[src]

type Output = Self

The resulting type after applying the - operator.

impl Sub<MicroSeconds> for Timeval[src]

type Output = Self

The resulting type after applying the - operator.

impl Sub<MicroSeconds> for UnixTs[src]

type Output = Self

The resulting type after applying the - operator.

impl SubAssign<Duration> for MicroSeconds[src]

impl SubAssign<MicroSeconds> for MicroSeconds[src]

impl SubAssign<MicroSeconds> for MonotonicTs[src]

impl SubAssign<MicroSeconds> for Timeval[src]

impl SubAssign<MicroSeconds> for UnixTs[src]

impl TryFrom<Duration> for MicroSeconds[src]

type Error = ()

The type returned in the event of a conversion error.

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, Rhs> NumAssignOps<Rhs> for T where
    T: AddAssign<Rhs> + SubAssign<Rhs> + MulAssign<Rhs> + DivAssign<Rhs> + RemAssign<Rhs>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.