[−][src]Struct ijson::number::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]
pub fn borrow_mut(&mut self) -> &mut IValue
[src]
impl Clone for INumber
[src]
impl Debug for INumber
[src]
impl Default for INumber
[src]
impl<'de> Deserialize<'de> for INumber
[src]
pub fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where
D: Deserializer<'de>,
[src]
D: Deserializer<'de>,
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
pub fn deserialize_any<V>(self, visitor: V) -> Result<V::Value, Error> where
V: Visitor<'de>,
[src]
V: Visitor<'de>,
pub fn deserialize_newtype_struct<V>(
self,
_name: &'static str,
visitor: V
) -> Result<V::Value, Error> where
V: Visitor<'de>,
[src]
self,
_name: &'static str,
visitor: V
) -> Result<V::Value, Error> where
V: Visitor<'de>,
pub fn deserialize_bool<V>(self, visitor: V) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
[src]
V: Visitor<'de>,
pub fn deserialize_i8<V>(self, visitor: V) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
[src]
V: Visitor<'de>,
pub fn deserialize_i16<V>(self, visitor: V) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
[src]
V: Visitor<'de>,
pub fn deserialize_i32<V>(self, visitor: V) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
[src]
V: Visitor<'de>,
pub fn deserialize_i64<V>(self, visitor: V) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
[src]
V: Visitor<'de>,
pub fn deserialize_i128<V>(self, visitor: V) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
[src]
V: Visitor<'de>,
pub fn deserialize_u8<V>(self, visitor: V) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
[src]
V: Visitor<'de>,
pub fn deserialize_u16<V>(self, visitor: V) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
[src]
V: Visitor<'de>,
pub fn deserialize_u32<V>(self, visitor: V) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
[src]
V: Visitor<'de>,
pub fn deserialize_u64<V>(self, visitor: V) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
[src]
V: Visitor<'de>,
pub fn deserialize_u128<V>(self, visitor: V) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
[src]
V: Visitor<'de>,
pub fn deserialize_f32<V>(self, visitor: V) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
[src]
V: Visitor<'de>,
pub fn deserialize_f64<V>(self, visitor: V) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
[src]
V: Visitor<'de>,
pub fn deserialize_char<V>(self, visitor: V) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
[src]
V: Visitor<'de>,
pub fn deserialize_str<V>(self, visitor: V) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
[src]
V: Visitor<'de>,
pub fn deserialize_string<V>(self, visitor: V) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
[src]
V: Visitor<'de>,
pub fn deserialize_bytes<V>(self, visitor: V) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
[src]
V: Visitor<'de>,
pub fn deserialize_byte_buf<V>(
self,
visitor: V
) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
[src]
self,
visitor: V
) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
pub fn deserialize_option<V>(self, visitor: V) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
[src]
V: Visitor<'de>,
pub fn deserialize_unit<V>(self, visitor: V) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
[src]
V: Visitor<'de>,
pub fn deserialize_unit_struct<V>(
self,
name: &'static str,
visitor: V
) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
[src]
self,
name: &'static str,
visitor: V
) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
pub fn deserialize_seq<V>(self, visitor: V) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
[src]
V: Visitor<'de>,
pub fn deserialize_tuple<V>(
self,
len: usize,
visitor: V
) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
[src]
self,
len: usize,
visitor: V
) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
pub fn deserialize_tuple_struct<V>(
self,
name: &'static str,
len: usize,
visitor: V
) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
[src]
self,
name: &'static str,
len: usize,
visitor: V
) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
pub fn deserialize_map<V>(self, visitor: V) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
[src]
V: Visitor<'de>,
pub fn deserialize_struct<V>(
self,
name: &'static str,
fields: &'static [&'static str],
visitor: V
) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
[src]
self,
name: &'static str,
fields: &'static [&'static str],
visitor: V
) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
pub fn deserialize_enum<V>(
self,
name: &'static str,
variants: &'static [&'static str],
visitor: V
) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
[src]
self,
name: &'static str,
variants: &'static [&'static str],
visitor: V
) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
pub fn deserialize_identifier<V>(
self,
visitor: V
) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
[src]
self,
visitor: V
) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
pub fn deserialize_ignored_any<V>(
self,
visitor: V
) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
[src]
self,
visitor: V
) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
pub fn is_human_readable(&self) -> bool
[src]
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]
pub fn hash<H: Hasher>(&self, state: &mut H)
[src]
pub fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl Ord for INumber
[src]
pub fn cmp(&self, other: &Self) -> Ordering
[src]
#[must_use]pub fn max(self, other: Self) -> Self
1.21.0[src]
#[must_use]pub fn min(self, other: Self) -> Self
1.21.0[src]
#[must_use]pub fn clamp(self, min: Self, max: Self) -> Self
[src]
impl PartialEq<INumber> for INumber
[src]
pub fn eq(&self, other: &Self) -> bool
[src]
#[must_use]pub fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
impl PartialOrd<INumber> for INumber
[src]
pub fn partial_cmp(&self, other: &Self) -> Option<Ordering>
[src]
#[must_use]pub fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn le(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn ge(&self, other: &Rhs) -> bool
1.0.0[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.
pub fn try_from(other: &'a IValue) -> Result<Self, ()>
[src]
impl<'a> TryFrom<&'a mut IValue> for &'a mut INumber
[src]
type Error = ()
The type returned in the event of a conversion error.
pub fn try_from(other: &'a mut IValue) -> Result<Self, ()>
[src]
impl TryFrom<IValue> for INumber
[src]
type Error = IValue
The type returned in the event of a conversion error.
pub fn try_from(other: IValue) -> Result<Self, IValue>
[src]
impl TryFrom<f32> for INumber
[src]
type Error = ()
The type returned in the event of a conversion error.
pub fn try_from(v: f32) -> Result<Self, ()>
[src]
impl TryFrom<f64> for INumber
[src]
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]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> DeserializeOwned for T where
T: for<'de> Deserialize<'de>,
[src]
T: for<'de> Deserialize<'de>,
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,