Trait fixed::traits::LosslessTryInto[][src]

pub trait LosslessTryInto<Dst> {
    fn lossless_try_into(self) -> Option<Dst>;
}
Expand description

This trait provides lossless conversions that might be fallible. This is the reciprocal of LosslessTryFrom.

Usually LosslessTryFrom should be implemented instead of this trait; there is a blanket implementation which provides this trait when LosslessTryFrom is implemented (similar to Into and From).

Examples

use fixed::traits::LosslessTryInto;
use fixed::types::{I24F8, I4F12};
// original is 0x000001.23, lossless is 0x1.230
let original = I24F8::from_bits(0x0000_0123);
let lossless: Option<I4F12> = original.lossless_try_into();
assert_eq!(lossless, Some(I4F12::from_bits(0x1230)));
// too_large is 0x000012.34, 0x12.340 does not fit in I4F12
let too_large = I24F8::from_bits(0x0000_1234);
let overflow: Option<I4F12> = too_large.lossless_try_into();
assert_eq!(overflow, None);

Required methods

fn lossless_try_into(self) -> Option<Dst>[src]

Expand description

Performs the conversion.

Loading content...

Implementors

impl<Src, Dst> LosslessTryInto<Dst> for Src where
    Dst: LosslessTryFrom<Src>, 
[src]

Loading content...