[][src]Struct ijson::IValue

#[repr(transparent)]pub struct IValue { /* fields omitted */ }

Stores an arbitrary JSON value.

Compared to serde_json::Value this type is a struct rather than an enum, as this is necessary to achieve the important size reductions. This means that you cannot directly match on an IValue to determine its type.

Instead, an IValue offers several ways to get at the inner type:

  • Destructuring using IValue::destructure[{_ref,_mut}]()

    These methods return wrapper enums which you can directly match on, so these methods are the most direct replacement for matching on a Value.

  • Borrowing using IValue::as_{array,object,string,number}[_mut]()

    These methods return an Option of the corresponding reference if the type matches the one expected. These methods exist for the variants which are not Copy.

  • Converting using IValue::into_{array,object,string,number}()

    These methods return a Result of the corresponding type (or the original IValue if the type is not the one expected). These methods also exist for the variants which are not Copy.

  • Getting using IValue::to_{bool,{i,u,f}{32,64}}[_lossy]}()

    These methods return an Option of the corresponding type. These methods exist for types where the return value would be Copy.

You can also check the type of the inner value without specifically accessing it using one of these methods:

  • Checking using IValue::is_{null,bool,number,string,array,object,true,false}()

    These methods exist for all types.

  • Getting the type with IValue::type_

    This method returns the ValueType enum, which has a variant for each of the six JSON types.

Implementations

impl IValue[src]

pub const NULL: Self[src]

JSON null.

pub const FALSE: Self[src]

JSON false.

pub const TRUE: Self[src]

JSON true.

pub fn type_(&self) -> ValueType[src]

Returns the type of this value.

pub fn destructure(self) -> Destructured[src]

Destructures this value into an enum which can be matched on.

pub fn destructure_ref(&self) -> DestructuredRef<'_>[src]

Destructures a reference to this value into an enum which can be matched on.

pub fn destructure_mut(&mut self) -> DestructuredMut<'_>[src]

Destructures a mutable reference to this value into an enum which can be matched on.

pub fn get(&self, index: impl ValueIndex) -> Option<&IValue>[src]

Indexes into this value with a number or string. Panics if the value is not an array or object. Panics if attempting to index an array with a string. Panics if attempting to index an object with a number. Returns None if the index type is correct, but there is no value at this index.

pub fn get_mut(&mut self, index: impl ValueIndex) -> Option<&mut IValue>[src]

Mutably indexes into this value with a number or string. Panics if the value is not an array or object. Panics if attempting to index an array with a string. Panics if attempting to index an object with a number. Returns None if the index type is correct, but there is no value at this index.

pub fn remove(&mut self, index: impl ValueIndex) -> Option<IValue>[src]

Removes a value at the specified numberic or string index. Panics if this is not an array or object. Panics if attempting to index an array with a string. Panics if attempting to index an object with a number. Returns None if the index type is correct, but there is no value at this index.

pub fn take(&mut self) -> IValue[src]

Takes this value, replacing it with IValue::NULL.

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

Returns the length of this value if it is an array or object. Returns None for other types.

pub fn is_empty(&self) -> Option<bool>[src]

Returns whether this value is empty if it is an array or object. Returns None for other types.

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

Returns true if this is the null value.

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

Returns true if this is a boolean.

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

Returns true if this is the true value.

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

Returns true if this is the false value.

pub fn to_bool(&self) -> Option<bool>[src]

Converts this value to a bool. Returns None if it's not a boolean.

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

Returns true if this is a number.

pub fn as_number(&self) -> Option<&INumber>[src]

Gets a reference to this value as an INumber. Returns None if it's not a number.

pub fn as_number_mut(&mut self) -> Option<&mut INumber>[src]

Gets a mutable reference to this value as an INumber. Returns None if it's not a number.

pub fn into_number(self) -> Result<INumber, IValue>[src]

Converts this value to an INumber. Returns Err(self) if it's not a number.

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

Converts this value to an i64 if it is a number that can be represented exactly.

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

Converts this value to a u64 if it is a number that can be represented exactly.

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

Converts this value to an f64 if it is a number that can be represented exactly.

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

Converts this value to an f32 if it is a number that can be represented exactly.

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

Converts this value to an i32 if it is a number that can be represented exactly.

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

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

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

Converts this value to an isize if it is a number that can be represented exactly.

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

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

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

Converts this value to an f64 if it is a number, potentially losing precision in the process.

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

Converts this value to an f32 if it is a number, potentially losing precision in the process.

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

Returns true if this is a string.

pub fn as_string(&self) -> Option<&IString>[src]

Gets a reference to this value as an IString. Returns None if it's not a string.

pub fn as_string_mut(&mut self) -> Option<&mut IString>[src]

Gets a mutable reference to this value as an IString. Returns None if it's not a string.

pub fn into_string(self) -> Result<IString, IValue>[src]

Converts this value to an IString. Returns Err(self) if it's not a string.

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

Returns true if this is an array.

pub fn as_array(&self) -> Option<&IArray>[src]

Gets a reference to this value as an IArray. Returns None if it's not an array.

pub fn as_array_mut(&mut self) -> Option<&mut IArray>[src]

Gets a mutable reference to this value as an IArray. Returns None if it's not an array.

pub fn into_array(self) -> Result<IArray, IValue>[src]

Converts this value to an IArray. Returns Err(self) if it's not an array.

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

Returns true if this is an object.

pub fn as_object(&self) -> Option<&IObject>[src]

Gets a reference to this value as an IObject. Returns None if it's not an object.

pub fn as_object_mut(&mut self) -> Option<&mut IObject>[src]

Gets a mutable reference to this value as an IObject. Returns None if it's not an object.

pub fn into_object(self) -> Result<IObject, IValue>[src]

Converts this value to an IObject. Returns Err(self) if it's not an object.

Trait Implementations

impl AsMut<IValue> for IArray[src]

impl AsMut<IValue> for INumber[src]

impl AsMut<IValue> for IObject[src]

impl AsMut<IValue> for IString[src]

impl AsRef<IValue> for IArray[src]

impl AsRef<IValue> for INumber[src]

impl AsRef<IValue> for IObject[src]

impl AsRef<IValue> for IString[src]

impl Borrow<IValue> for IArray[src]

impl Borrow<IValue> for INumber[src]

impl Borrow<IValue> for IObject[src]

impl Borrow<IValue> for IString[src]

impl BorrowMut<IValue> for IArray[src]

impl BorrowMut<IValue> for INumber[src]

impl BorrowMut<IValue> for IObject[src]

impl BorrowMut<IValue> for IString[src]

impl Clone for IValue[src]

impl Debug for IValue[src]

impl Default for IValue[src]

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

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

type Error = Error

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

impl Drop for IValue[src]

impl Eq for IValue[src]

impl<T: Into<IValue> + Clone, '_> From<&'_ [T]> for IValue[src]

impl<'_> From<&'_ String> for IValue[src]

impl<'_> From<&'_ mut String> for IValue[src]

impl<'_> From<&'_ mut str> for IValue[src]

impl<'_> From<&'_ str> for IValue[src]

impl<K: Into<IString>, V: Into<IValue>> From<BTreeMap<K, V>> for IValue[src]

impl<K: Into<IString>, V: Into<IValue>> From<HashMap<K, V, RandomState>> for IValue[src]

impl From<IArray> for IValue[src]

impl From<INumber> for IValue[src]

impl From<IObject> for IValue[src]

impl From<IString> for IValue[src]

impl<T: Into<IValue>> From<Option<T>> for IValue[src]

impl From<String> for IValue[src]

impl<T: Into<IValue>> From<Vec<T>> for IValue[src]

impl From<bool> for IValue[src]

impl From<f32> for IValue[src]

impl From<f64> for IValue[src]

impl From<i16> for IValue[src]

impl From<i32> for IValue[src]

impl From<i64> for IValue[src]

impl From<i8> for IValue[src]

impl From<isize> for IValue[src]

impl From<u16> for IValue[src]

impl From<u32> for IValue[src]

impl From<u64> for IValue[src]

impl From<u8> for IValue[src]

impl From<usize> for IValue[src]

impl Hash for IValue[src]

impl<I: ValueIndex> Index<I> for IValue[src]

type Output = IValue

The returned type after indexing.

impl<I: ValueIndex> IndexMut<I> for IValue[src]

impl PartialEq<IValue> for IValue[src]

impl PartialOrd<IValue> for IValue[src]

impl Send for IValue[src]

impl Serialize for IValue[src]

impl Sync for IValue[src]

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

type Error = ()

The type returned in the event of a conversion error.

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 IValue> for &'a IObject[src]

type Error = ()

The type returned in the event of a conversion error.

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

type Error = ()

The type returned in the event of a conversion error.

impl<'a> TryFrom<&'a mut IValue> for &'a mut IArray[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<'a> TryFrom<&'a mut IValue> for &'a mut IObject[src]

type Error = ()

The type returned in the event of a conversion error.

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

type Error = ()

The type returned in the event of a conversion error.

impl TryFrom<IValue> for IArray[src]

type Error = IValue

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<IValue> for IObject[src]

type Error = IValue

The type returned in the event of a conversion error.

impl TryFrom<IValue> for IString[src]

type Error = IValue

The type returned in the event of a conversion error.

Auto Trait Implementations

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.