[][src]Struct ijson::number::INumber

#[repr(transparent)]pub struct INumber(_);

The INumber type represents a JSON number. It is decoupled from any specific representation, and internally uses several. There is no way to determine the internal representation: instead the caller is expected to convert the number using one of the fallible to_xxx functions and handle the cases where the number does not convert to the desired type.

Special floating point values (eg. NaN, Infinity, etc.) cannot be stored within an INumber.

Whilst INumber does not consider 2.0 and 2 to be different numbers (ie. they will compare equal) it does allow you to distinguish them using the method INumber::has_decimal_point(). That said, calling to_i32 on 2.0 will succeed with the value 2.

Currently INumber can store any number representable with an f64, i64 or u64. It is expected that in the future it will be further expanded to store integers and possibly decimals to arbitrary precision, but that is not currently the case.

Any number representable with an i8 or a u8 can be stored in an INumber without a heap allocation (so JSON byte arrays are relatively efficient). Integers up to 24 bits can be stored with a 4-byte heap allocation.

Implementations

impl INumber[src]

pub fn zero() -> Self[src]

Returns the number zero (without a decimal point). Does not allocate.

pub fn one() -> Self[src]

Returns the number one (without a decimal point). Does not allocate.

pub fn to_i64(&self) -> Option<i64>[src]

Converts this number to an i64 if it can be represented exactly.

pub fn to_u64(&self) -> Option<u64>[src]

Converts this number to an f64 if it can be represented exactly.

pub fn to_f64(&self) -> Option<f64>[src]

Converts this number to an f64 if it can be represented exactly.

pub fn to_f32(&self) -> Option<f32>[src]

Converts this number to an f32 if it can be represented exactly.

pub fn to_i32(&self) -> Option<i32>[src]

Converts this number to an i32 if it can be represented exactly.

pub fn to_u32(&self) -> Option<u32>[src]

Converts this number to a u32 if it can be represented exactly.

pub fn to_isize(&self) -> Option<isize>[src]

Converts this number to an isize if it can be represented exactly.

pub fn to_usize(&self) -> Option<usize>[src]

Converts this number to a usize if it can be represented exactly.

pub fn to_f64_lossy(&self) -> f64[src]

Converts this number to an f64, potentially losing precision in the process.

pub fn to_f32_lossy(&self) -> f32[src]

Converts this number to an f32, potentially losing precision in the process.

pub fn has_decimal_point(&self) -> bool[src]

This allows distinguishing between 1.0 and 1 in the original JSON. Numeric operations will otherwise treat these two values as equivalent.

Trait Implementations

impl AsMut<IValue> for INumber[src]

impl AsRef<IValue> for INumber[src]

impl Borrow<IValue> for INumber[src]

impl BorrowMut<IValue> for INumber[src]

impl Clone for INumber[src]

impl Debug for INumber[src]

impl Default for INumber[src]

impl<'de> Deserialize<'de> for INumber[src]

impl<'de> Deserializer<'de> for &'de INumber[src]

type Error = Error

The error type that can be returned if some error occurs during deserialization. Read more

impl Eq for INumber[src]

impl From<INumber> for IValue[src]

impl From<i16> for INumber[src]

impl From<i32> for INumber[src]

impl From<i64> for INumber[src]

impl From<i8> for INumber[src]

impl From<isize> for INumber[src]

impl From<u16> for INumber[src]

impl From<u32> for INumber[src]

impl From<u64> for INumber[src]

impl From<u8> for INumber[src]

impl From<usize> for INumber[src]

impl Hash for INumber[src]

impl Ord for INumber[src]

impl PartialEq<INumber> for INumber[src]

impl PartialOrd<INumber> for INumber[src]

impl Serialize for INumber[src]

impl<'a> TryFrom<&'a IValue> for &'a INumber[src]

type Error = ()

The type returned in the event of a conversion error.

impl<'a> TryFrom<&'a mut IValue> for &'a mut INumber[src]

type Error = ()

The type returned in the event of a conversion error.

impl TryFrom<IValue> for INumber[src]

type Error = IValue

The type returned in the event of a conversion error.

impl TryFrom<f32> for INumber[src]

type Error = ()

The type returned in the event of a conversion error.

impl TryFrom<f64> for INumber[src]

type Error = ()

The type returned in the event of a conversion error.

Auto Trait Implementations

impl RefUnwindSafe for INumber

impl Send for INumber

impl Sync for INumber

impl Unpin for INumber

impl UnwindSafe for INumber

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> DeserializeOwned for T where
    T: for<'de> Deserialize<'de>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.