1 2 3 4 5 6 7 8
use num_traits::cast::{NumCast, cast}; use error::{self, ErrorKind}; pub fn safe_cast<T: NumCast, U: NumCast>(n: T) -> error::Result<U> { cast(n).ok_or(ErrorKind::IntegerCast.into()) }