[−][src]Trait embedded_time::duration::TryConvertInto
Required methods
fn try_convert_into(self) -> Option<Dest>
Implementors
impl<Source, Dest> TryConvertInto<Dest> for Source where
Source: Duration,
Dest: Duration + TryConvertFrom<Source>,
[src]
Source: Duration,
Dest: Duration + TryConvertFrom<Source>,
The reciprocal of TryConvertFrom
Examples
assert_eq!(Seconds(23_000_i64).try_convert_into(), Some(Seconds(23_000_i32))); assert_eq!(Seconds(23_000_i32).try_convert_into(), Some(Seconds(23_000_i32))); assert_eq!(Some(Seconds(23_000_i64)), (Seconds(23_000_i32).try_convert_into())); assert_eq!(Milliseconds(23_000_i64).try_convert_into(), Some(Seconds(23_i32))); assert_eq!(Milliseconds(23_000_i32).try_convert_into(), Some(Seconds(23_i64)));
Errors
the conversion of periods causes an overflow:
assert_eq!(Seconds(i32::MAX).try_convert_into(), None::<Milliseconds<i32>>);
the Self integer cast to that of the destination type fails
assert_eq!(Seconds(i32::MAX as i64 + 1).try_convert_into(), None::<Seconds<i32>>);
Returns
None
if the result of the conversion does not fit in the requested Duration
type