pub struct Number(/* private fields */);Expand description
A JSON number value, stored as its original string representation.
Validation is delegated to serde_json’s number parser, so any string accepted here
is guaranteed to be a valid JSON number. NaN and infinity are rejected.
§Construction
use tjson::Number;
let n: Number = "42".parse().unwrap();
let n: Number = "-3.14".parse().unwrap();
let n: Number = "1e100".parse().unwrap();
assert!(Number::try_from(f64::NAN).is_err());
assert!(Number::try_from(f64::INFINITY).is_err());Implementations§
Source§impl Number
impl Number
Sourcepub fn as_u64(&self) -> Option<u64>
pub fn as_u64(&self) -> Option<u64>
Returns the value as a u64 if it is a non-negative integer that fits.
Sourcepub fn as_f64(&self) -> Option<f64>
pub fn as_f64(&self) -> Option<f64>
Returns the value as an f64.
Returns None only if the string somehow fails to parse as a float, which cannot
happen for any Number constructed through the public API. Large integers and
high-precision decimals may lose precision in the conversion.
Sourcepub fn is_integer(&self) -> bool
pub fn is_integer(&self) -> bool
Returns true if the number has no fractional or exponent part.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Number
impl<'de> Deserialize<'de> for Number
Source§fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
Deserialize this value from the given Serde deserializer. Read more
impl Eq for Number
impl StructuralPartialEq for Number
Auto Trait Implementations§
impl Freeze for Number
impl RefUnwindSafe for Number
impl Send for Number
impl Sync for Number
impl Unpin for Number
impl UnsafeUnpin for Number
impl UnwindSafe for Number
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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.