summaryrefslogtreecommitdiffstats
path: root/vendor/serde_json/src/number.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-07 05:48:48 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-07 05:48:48 +0000
commitef24de24a82fe681581cc130f342363c47c0969a (patch)
tree0d494f7e1a38b95c92426f58fe6eaa877303a86c /vendor/serde_json/src/number.rs
parentReleasing progress-linux version 1.74.1+dfsg1-1~progress7.99u1. (diff)
downloadrustc-ef24de24a82fe681581cc130f342363c47c0969a.tar.xz
rustc-ef24de24a82fe681581cc130f342363c47c0969a.zip
Merging upstream version 1.75.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/serde_json/src/number.rs')
-rw-r--r--vendor/serde_json/src/number.rs27
1 files changed, 27 insertions, 0 deletions
diff --git a/vendor/serde_json/src/number.rs b/vendor/serde_json/src/number.rs
index 7ff66681d..b0231a87b 100644
--- a/vendor/serde_json/src/number.rs
+++ b/vendor/serde_json/src/number.rs
@@ -279,6 +279,33 @@ impl Number {
}
}
+ /// Returns the exact original JSON representation that this Number was
+ /// parsed from.
+ ///
+ /// For numbers constructed not via parsing, such as by `From<i32>`, returns
+ /// the JSON representation that serde\_json would serialize for this
+ /// number.
+ ///
+ /// ```
+ /// # use serde_json::Number;
+ /// for value in [
+ /// "7",
+ /// "12.34",
+ /// "34e-56789",
+ /// "0.0123456789000000012345678900000001234567890000123456789",
+ /// "343412345678910111213141516171819202122232425262728293034",
+ /// "-343412345678910111213141516171819202122232425262728293031",
+ /// ] {
+ /// let number: Number = serde_json::from_str(value).unwrap();
+ /// assert_eq!(number.as_str(), value);
+ /// }
+ /// ```
+ #[cfg(feature = "arbitrary_precision")]
+ #[cfg_attr(docsrs, doc(cfg(feature = "arbitrary_precision")))]
+ pub fn as_str(&self) -> &str {
+ &self.n
+ }
+
pub(crate) fn as_f32(&self) -> Option<f32> {
#[cfg(not(feature = "arbitrary_precision"))]
match self.n {