[−][src]Trait embedded_time::duration::TryConvertFrom
Required methods
fn try_convert_from(other: Source) -> Option<Self>
Implementors
impl<Source, Dest> TryConvertFrom<Source> for Dest where
Dest: Duration,
Dest::Rep: TimeRep + TryFrom<Source::Rep, Error: Debug>,
Source: Duration,
Source::Rep: TimeRep,
[src]
Dest: Duration,
Dest::Rep: TimeRep + TryFrom<Source::Rep, Error: Debug>,
Source: Duration,
Source::Rep: TimeRep,
fn try_convert_from(source: Source) -> Option<Self>
[src]
Attempt to convert from one duration type to another
Both the underlying storage type and the LSbit period can be converted
Errors
- unable to cast underlying types
- LSbit period conversion overflow
Examples
assert_eq!(Seconds::<i32>::try_convert_from(Milliseconds(23_000_i64)), Some(Seconds(23_i32))); assert_eq!(Seconds::<i64>::try_convert_from(Milliseconds(23_000_i32)), Some(Seconds(23_i64)));
Errors
the conversion of periods causes an overflow:
assert_eq!(Milliseconds::<i32>::try_convert_from(Seconds(i32::MAX)), None);
the Self integer cast to that of the provided type fails
assert_eq!(Seconds::<i32>::try_convert_from(Seconds(i32::MAX as i64 + 1)), None);
Returns
None
if the result of the conversion does not fit in the requested integer size