[][src]Struct embedded_time::duration::units::Milliseconds

pub struct Milliseconds<T: TimeInt = u32>(pub T);

A duration unit type

Trait Implementations

impl<T: TimeInt, Rhs: Duration> Add<Rhs> for Milliseconds<T> where
    Rhs: FixedPoint,
    T: TryFrom<Rhs::T>, 
[src]

type Output = Self

The resulting type after applying the + operator.

fn add(self, rhs: Rhs) -> Self::Output[src]

Returns the sum as the LHS type

Examples

assert_eq!((Milliseconds(1_u32) + Seconds(1_u32)),
    Milliseconds(1_001_u32));

Panics

The same reason the integer operation would panic. Namely, if the result overflows the type.

This example panics
let _ = Seconds(u32::MAX) + Seconds(1_u32);

impl<T: Clone + TimeInt> Clone for Milliseconds<T>[src]

impl<T: Copy + TimeInt> Copy for Milliseconds<T>[src]

impl<T: Debug + TimeInt> Debug for Milliseconds<T>[src]

impl<T: TimeInt> Display for Milliseconds<T>[src]

fn fmt(&self, f: &mut Formatter) -> Result[src]

Just forwards the underlying integer to core::fmt::Display::fmt()

assert_eq!(format!("{}", Seconds(123_u32)), "123");

impl<T: TimeInt> Duration for Milliseconds<T>[src]

impl<T: Eq + TimeInt> Eq for Milliseconds<T>[src]

impl<T: Ord + TimeInt> Ord for Milliseconds<T>[src]

impl<T: TimeInt, Rhs: Duration> PartialEq<Rhs> for Milliseconds<T> where
    T: TryFrom<Rhs::T>,
    Rhs: FixedPoint,
    Rhs::T: TryFrom<T>, 
[src]

fn eq(&self, rhs: &Rhs) -> bool[src]

assert_eq!(Seconds(123_u32), Milliseconds(123_000_u64));
assert_ne!(Seconds(123_u32), Milliseconds(123_001_u64));

impl<T: TimeInt, Rhs: Duration> PartialOrd<Rhs> for Milliseconds<T> where
    T: TryFrom<Rhs::T>,
    Rhs: FixedPoint,
    Rhs::T: TryFrom<T>, 
[src]

fn partial_cmp(&self, rhs: &Rhs) -> Option<Ordering>[src]


assert!(Seconds(2_u64) < Milliseconds(2_001_u32));
assert!(Seconds(2_u32) > Milliseconds(1_999_u32));

impl<T: TimeInt, Rhs: Duration> Rem<Rhs> for Milliseconds<T> where
    T: TryFrom<Rhs::T>,
    Rhs: FixedPoint, 
[src]

type Output = Self

The resulting type after applying the % operator.

fn rem(self, rhs: Rhs) -> Self::Output[src]

Returns the remainder as the LHS type

assert_eq!(Minutes(62_u32) % Hours(1_u32), Minutes(2_u32));

impl<T: TimeInt> StructuralEq for Milliseconds<T>[src]

impl<T: TimeInt, Rhs: Duration> Sub<Rhs> for Milliseconds<T> where
    T: TryFrom<Rhs::T>,
    Rhs: FixedPoint, 
[src]

type Output = Self

The resulting type after applying the - operator.

fn sub(self, rhs: Rhs) -> Self::Output[src]

Returns the difference as the LHS type

Examples

assert_eq!((Milliseconds(2_001_u32) - Seconds(1_u32)),
    Milliseconds(1_001_u32));

Panics

The same reason the integer operation would panic. Namely, if the result overflows the type.

This example panics
let _ = Seconds(0_u32) - Seconds(1_u32);

impl<T: TimeInt> TryFrom<Duration> for Milliseconds<T>[src]

type Error = ConversionError

The type returned in the event of a conversion error.

fn try_from(core_duration: Duration) -> Result<Self, Self::Error>[src]

Construct an embedded_time::Duration from a core::time::Duration

Examples

let core_duration = core::time::Duration::new(5, 730023852);
assert_eq!(Milliseconds::<u32>::try_from(core_duration), Ok(5_730.milliseconds()));
let duration: Result<Milliseconds<u32>, _> =
    core::time::Duration::new(5, 730023852).try_into();
assert_eq!(duration, Ok(5_730.milliseconds()));

Errors

ConversionError::ConversionFailure : The result doesn't fit in the specified type

assert_eq!(
    Milliseconds::<u32>::try_from(core::time::Duration::from_millis((u32::MAX as u64) + 1)),
    Err(ConversionError::ConversionFailure)
);

let duration: Result<Milliseconds<u32>, _> =
    core::time::Duration::from_millis((u32::MAX as u64) + 1).try_into();
assert_eq!(duration, Err(ConversionError::ConversionFailure));

impl<SourceInt: TimeInt, DestInt: TimeInt> TryFrom<Generic<SourceInt>> for Milliseconds<DestInt> where
    DestInt: TryFrom<SourceInt>, 
[src]

type Error = ConversionError

The type returned in the event of a conversion error.

fn try_from(generic_duration: Generic<SourceInt>) -> Result<Self, Self::Error>[src]

Construct a named Duration from a Generic Duration

Examples

assert_eq!(
    Seconds::<u64>::try_from(Generic::new(2_000_u32, Fraction::new(1, 1_000))),
    Ok(Seconds(2_u64))
);

// TryInto also works
assert_eq!(
    Generic::new(2_000_u64, Fraction::new(1, 1_000)).try_into(),
    Ok(Seconds(2_u64))
);

Errors

Failure will only occur if the provided value does not fit in the selected destination type.


ConversionError::Overflow : The conversion of the scaling factor causes an overflow.

assert_eq!(
    Seconds::<u32>::try_from(Generic::new(u32::MAX, Fraction::new(10,1))),
    Err(ConversionError::Overflow)
);

ConversionError::ConversionFailure : The integer conversion to that of the destination type fails.

assert_eq!(
    Seconds::<u32>::try_from(Generic::new(u32::MAX as u64 + 1, Fraction::new(1,1))),
    Err(ConversionError::ConversionFailure)
);

impl<T: TimeInt> TryFrom<Milliseconds<T>> for Duration[src]

type Error = ConversionError

The type returned in the event of a conversion error.

fn try_from(duration: Milliseconds<T>) -> Result<Self, Self::Error>[src]

Construct a core::time::Duration from an embedded_time::Duration

let core_duration = core::time::Duration::try_from(2_569_u32.milliseconds()).unwrap();
assert_eq!(core_duration.as_secs(), 2);
assert_eq!(core_duration.subsec_nanos(), 569_000_000);
let core_duration: core::time::Duration = 2_569_u32.milliseconds().try_into().unwrap();
assert_eq!(core_duration.as_secs(), 2);
assert_eq!(core_duration.subsec_nanos(), 569_000_000);

Auto Trait Implementations

impl<T> RefUnwindSafe for Milliseconds<T> where
    T: RefUnwindSafe

impl<T> Send for Milliseconds<T> where
    T: Send

impl<T> Sync for Milliseconds<T> where
    T: Sync

impl<T> Unpin for Milliseconds<T> where
    T: Unpin

impl<T> UnwindSafe for Milliseconds<T> where
    T: UnwindSafe

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