diff --git a/src/value/mod.rs b/src/value/mod.rs index 4f1d4878e..d109747e4 100644 --- a/src/value/mod.rs +++ b/src/value/mod.rs @@ -495,6 +495,25 @@ impl Value { } } + /// Returns true if the `Value` is a Number. Returns false otherwise. + /// + /// ``` + /// # use serde_json::json; + /// # + /// let v = json!({ "a": 1, "b": "2" }); + /// + /// assert!(v["a"].is_number()); + /// + /// // The string `"2"` is a string, not a number. + /// assert!(!v["b"].is_number()); + /// ``` + pub fn is_number(&self) -> bool { + match *self { + Value::Number(_) => true, + _ => false, + } + } + /// If the `Value` is an Number, returns the associated [`Number`]. Returns /// None otherwise. /// @@ -517,25 +536,6 @@ impl Value { } } - /// Returns true if the `Value` is a Number. Returns false otherwise. - /// - /// ``` - /// # use serde_json::json; - /// # - /// let v = json!({ "a": 1, "b": "2" }); - /// - /// assert!(v["a"].is_number()); - /// - /// // The string `"2"` is a string, not a number. - /// assert!(!v["b"].is_number()); - /// ``` - pub fn is_number(&self) -> bool { - match *self { - Value::Number(_) => true, - _ => false, - } - } - /// Returns true if the `Value` is an integer between `i64::MIN` and /// `i64::MAX`. ///