Skip to content

Commit

Permalink
Allow arbitrarily large i128 in arbitrary_precision mode
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Oct 18, 2024
1 parent c3149ef commit f699506
Showing 1 changed file with 14 additions and 24 deletions.
38 changes: 14 additions & 24 deletions src/number.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,33 +314,23 @@ impl Number {
/// ```
#[inline]
pub fn from_i128(i: i128) -> Option<Number> {
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
Expand Down

0 comments on commit f699506

Please sign in to comment.