From aab7098acd584a115d6b0a9b2f2332830444b969 Mon Sep 17 00:00:00 2001 From: Dan Barella Date: Mon, 29 Jan 2018 19:38:31 -0500 Subject: [PATCH] Reformat macros. --- src/cast.rs | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/src/cast.rs b/src/cast.rs index 94230ae..58f5a90 100644 --- a/src/cast.rs +++ b/src/cast.rs @@ -239,31 +239,25 @@ macro_rules! impl_to_primitive_float_to_float { } macro_rules! impl_to_primitive_float_to_signed_int { - ($SrcT:ident, $DstT:ident, $slf:expr) => ( + ($SrcT:ident, $DstT:ident, $slf:expr) => ({ let t = $slf.trunc(); - if t >= $DstT::MIN as $SrcT && t <= $DstT::MAX as $SrcT { + if t >= $DstT::min_value() as $SrcT && t <= $DstT::max_value() as $SrcT { Some($slf as $DstT) } else { None } - ) + }) } macro_rules! impl_to_primitive_float_to_unsigned_int { - ($SrcT:ident, $DstT:ident, $slf:expr) => ( - if size_of::<$SrcT>() <= size_of::<$DstT>() { + ($SrcT:ident, $DstT:ident, $slf:expr) => ({ + let t = $slf.trunc(); + if t >= $DstT::min_value() as $SrcT && t <= $DstT::max_value() as $SrcT { Some($slf as $DstT) } else { - // Make sure the value is in range for the cast. - let n = $slf as $DstT; - let max_value: $DstT = ::std::$DstT::MAX; - if n <= max_value as $DstT { - Some($slf as $DstT) - } else { - None - } + None } - ) + }) } macro_rules! impl_to_primitive_float {