Skip to content

Commit

Permalink
adds as_str to Number if arbitrary_precision is enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
chanced committed Sep 6, 2023
1 parent 6525ffa commit 4cc9ea7
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/number.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,16 @@ impl Number {
}
}

/// Returns the `&str` representation of the `Number`.
/// ```
/// # use serde_json::Number;
///
/// assert_eq!(Number::from_f64(256.0).unwrap().as_str(), "256.0");
/// assert_eq!(Number::from_f64(34.0).unwrap().as_str(), "34.0");
pub fn as_str(&self) -> &str {
&self.n
}

pub(crate) fn as_f32(&self) -> Option<f32> {
#[cfg(not(feature = "arbitrary_precision"))]
match self.n {
Expand Down

0 comments on commit 4cc9ea7

Please sign in to comment.