pub struct RawNumber { /* private fields */ }
Expand description
Represents a JSON number with arbitrary precision, the underlying representation of a string,
like as Golang json.Number
.
Example1:
use sonic_rs::RawNumber;
use crate::sonic_rs::JsonNumberTrait;
// RawNumber can be parsed from a JSON number text.
let num: RawNumber = sonic_rs::from_str("123").unwrap();
assert_eq!(num.as_i64(), Some(123));
assert_eq!(num.as_str(), "123");
// RawNumber can be parsed from a JSON string text that contains a number.
let num: RawNumber =
sonic_rs::from_str("\"1.2333333333333333333333333333333333333333\"").unwrap();
assert_eq!(num.as_f64(), Some(1.2333333333333334));
assert_eq!(num.as_str(), "1.2333333333333333333333333333333333333333");
Implementations§
Trait Implementations§
Source§impl<'de> Deserialize<'de> for RawNumber
impl<'de> Deserialize<'de> for RawNumber
Source§fn deserialize<D>(deserializer: D) -> Result<RawNumber, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<RawNumber, D::Error>where
D: Deserializer<'de>,
Source§impl JsonNumberTrait for RawNumber
impl JsonNumberTrait for RawNumber
Source§fn is_i64(&self) -> bool
fn is_i64(&self) -> bool
Returns true if the Number
is an integer between i64::MIN
and
i64::MAX
.
For any Number on which is_i64
returns true, as_i64
is guaranteed to
return the integer value.
Source§fn is_u64(&self) -> bool
fn is_u64(&self) -> bool
Returns true if the Number
is an integer between zero and u64::MAX
.
For any Number on which is_u64
returns true, as_u64
is guaranteed to
return the integer value.
Source§fn is_f64(&self) -> bool
fn is_f64(&self) -> bool
Returns true if the Number
can be represented by f64.
For any Number on which is_f64
returns true, as_f64
is guaranteed to
return the floating point value.
Currently this function returns true if and only if both is_i64
and
is_u64
return false but this is not a guarantee in the future.
Source§fn as_i64(&self) -> Option<i64>
fn as_i64(&self) -> Option<i64>
If the Number
is an integer, represent it as i64 if possible. Returns
None otherwise.
impl Eq for RawNumber
impl StructuralPartialEq for RawNumber
Auto Trait Implementations§
impl !Freeze for RawNumber
impl RefUnwindSafe for RawNumber
impl Send for RawNumber
impl Sync for RawNumber
impl Unpin for RawNumber
impl UnwindSafe for RawNumber
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)