Flatten logic in Number::from_i128

This commit is contained in:
David Tolnay 2024-10-18 08:10:50 -07:00
parent 22973d2783
commit c3149efd62
No known key found for this signature in database
GPG Key ID: F9BA143B95FF6D82

View File

@ -314,8 +314,7 @@ impl Number {
/// ``` /// ```
#[inline] #[inline]
pub fn from_i128(i: i128) -> Option<Number> { pub fn from_i128(i: i128) -> Option<Number> {
match u64::try_from(i) { if let Ok(u) = u64::try_from(i) {
Ok(u) => {
let n = { let n = {
#[cfg(not(feature = "arbitrary_precision"))] #[cfg(not(feature = "arbitrary_precision"))]
{ {
@ -327,9 +326,7 @@ impl Number {
} }
}; };
Some(Number { n }) Some(Number { n })
} } else if let Ok(i) = i64::try_from(i) {
Err(_) => match i64::try_from(i) {
Ok(i) => {
let n = { let n = {
#[cfg(not(feature = "arbitrary_precision"))] #[cfg(not(feature = "arbitrary_precision"))]
{ {
@ -341,9 +338,8 @@ impl Number {
} }
}; };
Some(Number { n }) Some(Number { n })
} } else {
Err(_) => None, None
},
} }
} }