[][src]Struct embedded_time::duration::Generic

pub struct Generic<T> { /* fields omitted */ }

The Generic Duration type allows arbitrary _scaling factor_s to be used without having to impl FixedPoint.

The purpose of this type is to allow a simple Duration that can be defined at run-time. It does this by replacing the const scaling factor with a struct field.

Implementations

impl<T> Generic<T>[src]

pub const fn new(integer: T, scaling_factor: Fraction) -> Self[src]

Constructs a new (ram) fixed-point Generic Duration value

pub const fn integer(&self) -> &T[src]

Returns the integer value

pub const fn scaling_factor(&self) -> &Fraction[src]

Returns the scaling factor Fraction value

Trait Implementations

impl<T: Clone> Clone for Generic<T>[src]

impl<T: Copy> Copy for Generic<T>[src]

impl<T: Debug> Debug for Generic<T>[src]

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

impl<T: Eq> Eq for Generic<T>[src]

impl<T: PartialEq> PartialEq<Generic<T>> for Generic<T>[src]

impl<T> StructuralEq for Generic<T>[src]

impl<T> StructuralPartialEq for Generic<T>[src]

impl<SourceInt: TimeInt, DestInt: TimeInt> TryFrom<Generic<SourceInt>> for Hours<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<SourceInt: TimeInt, DestInt: TimeInt> TryFrom<Generic<SourceInt>> for Minutes<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<SourceInt: TimeInt, DestInt: TimeInt> TryFrom<Generic<SourceInt>> for Seconds<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<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<SourceInt: TimeInt, DestInt: TimeInt> TryFrom<Generic<SourceInt>> for Microseconds<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<SourceInt: TimeInt, DestInt: TimeInt> TryFrom<Generic<SourceInt>> for Nanoseconds<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)
);

Auto Trait Implementations

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

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

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

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

impl<T> UnwindSafe for Generic<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, 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.