[][src]Trait embedded_time::duration::TryConvertInto

pub trait TryConvertInto<Dest> {
    fn try_convert_into(self) -> Option<Dest>;
}

Required methods

fn try_convert_into(self) -> Option<Dest>

Loading content...

Implementors

impl<Source, Dest> TryConvertInto<Dest> for Source where
    Source: Duration,
    Dest: Duration + TryConvertFrom<Source>, 
[src]

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

Loading content...