Skip to content

Commit

Permalink
Reorder Value::as_number after is_number
Browse files Browse the repository at this point in the history
The other as_* methods all come after the corresponding is_* method.
  • Loading branch information
dtolnay committed Sep 9, 2023
1 parent 6a5fef9 commit 5a39516
Showing 1 changed file with 19 additions and 19 deletions.
38 changes: 19 additions & 19 deletions src/value/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///
Expand All @@ -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`.
///
Expand Down

0 comments on commit 5a39516

Please sign in to comment.