replaced else if with .map() and .or_else()
@@ -88,15 +88,9 @@ pub enum Number {
impl Number {
pub fn from_serde_number(n: &serde_json::Number) -> Option<Self> {
- if let Some(num) = n.as_u64() {
- Some(Number::PosInt(num))
- } else if let Some(num) = n.as_i64() {
- Some(Number::NegInt(num))
- } else if let Some(num) = n.as_f64() {
- Some(Number::Float(num))
- } else {
- None
- }
+ n.as_u64().map(Number::PosInt)
+ .or_else(|| n.as_i64().map(Number::NegInt))
+ .or_else(|| n.as_f64().map(Number::Float))
}
#[inline]
