diff --git a/src/number.rs b/src/number.rs index 718c0d744..c3e156e6e 100644 --- a/src/number.rs +++ b/src/number.rs @@ -314,33 +314,23 @@ impl Number { /// ``` #[inline] pub fn from_i128(i: i128) -> Option { - if let Ok(u) = u64::try_from(i) { - let n = { - #[cfg(not(feature = "arbitrary_precision"))] - { + let n = { + #[cfg(not(feature = "arbitrary_precision"))] + { + if let Ok(u) = u64::try_from(i) { N::PosInt(u) - } - #[cfg(feature = "arbitrary_precision")] - { - u.to_string() - } - }; - Some(Number { n }) - } else if let Ok(i) = i64::try_from(i) { - let n = { - #[cfg(not(feature = "arbitrary_precision"))] - { + } else if let Ok(i) = i64::try_from(i) { N::NegInt(i) + } else { + return None; } - #[cfg(feature = "arbitrary_precision")] - { - i.to_string() - } - }; - Some(Number { n }) - } else { - None - } + } + #[cfg(feature = "arbitrary_precision")] + { + i.to_string() + } + }; + Some(Number { n }) } /// Returns the exact original JSON representation that this Number was