Skip to main content

IObject

Struct IObject 

Source
pub struct IObject(/* private fields */);
Expand description

The IObject type is similar to a HashMap<IString, IValue>. As with the IArray, the length and capacity are stored inside the heap allocation. In addition, IObjects preserve the insertion order of their elements, in case that is important in the original JSON.

Removing from an IObject will disrupt the insertion order.

Implementations§

Source§

impl IObject

Source

pub fn new() -> Self

Constructs a new empty IObject. Does not allocate.

Source

pub fn with_capacity(cap: usize) -> Self

Constructs a new IObject with the specified capacity. At least that many entries can be added to the object without reallocating.

Source

pub fn capacity(&self) -> usize

Returns the capacity of the object. This is the maximum number of entries the object can hold without reallocating.

Source

pub fn len(&self) -> usize

Returns the number of entries currently stored in the object.

Source

pub fn is_empty(&self) -> bool

Returns true if the object is empty.

Source

pub fn reserve(&mut self, additional: usize)

Reserves space for at least this many additional entries.

Source

pub fn entry<'a>(&'a mut self, key: impl Into<IString>) -> Entry<'a>

Returns a view of an entry within this object.

Source

pub fn entry_or_clone<'a>(&'a mut self, key: &IString) -> Entry<'a>

Returns a view of an entry within this object, whilst avoiding cloning the key if the entry is already occupied.

Source

pub fn keys(&self) -> impl Iterator<Item = &IString>

Returns an iterator over references to the keys in this object.

Source

pub fn values(&self) -> impl Iterator<Item = &IValue>

Returns an iterator over references to the values in this object.

Source

pub fn iter<'a>(&'a self) -> Iter<'a>

Returns an iterator over (&key, &value) pairs in this object.

Source

pub fn values_mut(&mut self) -> impl Iterator<Item = &mut IValue>

Returns an iterator over mutable references to the values in this object.

Source

pub fn iter_mut<'a>(&'a mut self) -> IterMut<'a>

Returns an iterator over (&key, &mut value) pairs in this object.

Source

pub fn clear(&mut self)

Removes all entries from the object. The capacity is unchanged.

Source

pub fn get_key_value(&self, k: impl ObjectIndex) -> Option<(&IString, &IValue)>

Looks up the specified key in this object and returns a (&key, &value) pair if found.

Source

pub fn get_key_value_mut( &mut self, k: impl ObjectIndex, ) -> Option<(&IString, &mut IValue)>

Looks up the specified key in this object and returns a (&key, &mut value) pair if found.

Source

pub fn get(&self, k: impl ObjectIndex) -> Option<&IValue>

Looks up the specified key in this object and returns a reference to the corresponding value if found.

Source

pub fn get_mut(&mut self, k: impl ObjectIndex) -> Option<&mut IValue>

Looks up the specified key in this object and returns a mutable reference to the corresponding value if found.

Source

pub fn contains_key(&self, k: impl ObjectIndex) -> bool

Returns true if the specified key exists in the object.

Source

pub fn insert( &mut self, k: impl Into<IString>, v: impl Into<IValue>, ) -> Option<IValue>

Inserts a new value into this object with the specified key. If a value already existed at this key, that value is replaced and returend.

Source

pub fn remove_entry(&mut self, k: impl ObjectIndex) -> Option<(IString, IValue)>

Removes the entry at the specified key, returning both the key and value if found.

Source

pub fn remove(&mut self, k: impl ObjectIndex) -> Option<IValue>

Removes the entry at the specified key, returning the value if found.

Source

pub fn shrink_to_fit(&mut self)

Shrinks the memory allocation used by the object such that its capacity becomes equal to its length.

Source

pub fn retain(&mut self, f: impl FnMut(&IString, &mut IValue) -> bool)

Calls the specified function for each entry in the object. Each entry where the function returns false is removed from the object.

The function also has the ability to modify the values in-place.

Trait Implementations§

Source§

impl AsMut<IValue> for IObject

Source§

fn as_mut(&mut self) -> &mut IValue

Converts this type into a mutable reference of the (usually inferred) input type.
Source§

impl AsRef<IValue> for IObject

Source§

fn as_ref(&self) -> &IValue

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl Borrow<IValue> for IObject

Source§

fn borrow(&self) -> &IValue

Immutably borrows from an owned value. Read more
Source§

impl BorrowMut<IValue> for IObject

Source§

fn borrow_mut(&mut self) -> &mut IValue

Mutably borrows from an owned value. Read more
Source§

impl Clone for IObject

Source§

fn clone(&self) -> IObject

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for IObject

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for IObject

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for IObject

Source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<'de> Deserializer<'de> for &'de IObject

Source§

type Error = Error

The error type that can be returned if some error occurs during deserialization.
Source§

fn deserialize_any<V>(self, visitor: V) -> Result<V::Value, Error>
where V: Visitor<'de>,

Require the Deserializer to figure out how to drive the visitor based on what data type is in the input. Read more
Source§

fn deserialize_enum<V>( self, _name: &'static str, _variants: &'static [&'static str], visitor: V, ) -> Result<V::Value, Error>
where V: Visitor<'de>,

Hint that the Deserialize type is expecting an enum value with a particular name and possible variants.
Source§

fn deserialize_newtype_struct<V>( self, _name: &'static str, visitor: V, ) -> Result<V::Value, Error>
where V: Visitor<'de>,

Hint that the Deserialize type is expecting a newtype struct with a particular name.
Source§

fn deserialize_bool<V>( self, visitor: V, ) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where V: Visitor<'de>,

Hint that the Deserialize type is expecting a bool value.
Source§

fn deserialize_i8<V>( self, visitor: V, ) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where V: Visitor<'de>,

Hint that the Deserialize type is expecting an i8 value.
Source§

fn deserialize_i16<V>( self, visitor: V, ) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where V: Visitor<'de>,

Hint that the Deserialize type is expecting an i16 value.
Source§

fn deserialize_i32<V>( self, visitor: V, ) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where V: Visitor<'de>,

Hint that the Deserialize type is expecting an i32 value.
Source§

fn deserialize_i64<V>( self, visitor: V, ) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where V: Visitor<'de>,

Hint that the Deserialize type is expecting an i64 value.
Source§

fn deserialize_i128<V>( self, visitor: V, ) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where V: Visitor<'de>,

Hint that the Deserialize type is expecting an i128 value. Read more
Source§

fn deserialize_u8<V>( self, visitor: V, ) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where V: Visitor<'de>,

Hint that the Deserialize type is expecting a u8 value.
Source§

fn deserialize_u16<V>( self, visitor: V, ) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where V: Visitor<'de>,

Hint that the Deserialize type is expecting a u16 value.
Source§

fn deserialize_u32<V>( self, visitor: V, ) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where V: Visitor<'de>,

Hint that the Deserialize type is expecting a u32 value.
Source§

fn deserialize_u64<V>( self, visitor: V, ) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where V: Visitor<'de>,

Hint that the Deserialize type is expecting a u64 value.
Source§

fn deserialize_u128<V>( self, visitor: V, ) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where V: Visitor<'de>,

Hint that the Deserialize type is expecting an u128 value. Read more
Source§

fn deserialize_f32<V>( self, visitor: V, ) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where V: Visitor<'de>,

Hint that the Deserialize type is expecting a f32 value.
Source§

fn deserialize_f64<V>( self, visitor: V, ) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where V: Visitor<'de>,

Hint that the Deserialize type is expecting a f64 value.
Source§

fn deserialize_char<V>( self, visitor: V, ) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where V: Visitor<'de>,

Hint that the Deserialize type is expecting a char value.
Source§

fn deserialize_str<V>( self, visitor: V, ) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where V: Visitor<'de>,

Hint that the Deserialize type is expecting a string value and does not benefit from taking ownership of buffered data owned by the Deserializer. Read more
Source§

fn deserialize_string<V>( self, visitor: V, ) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where V: Visitor<'de>,

Hint that the Deserialize type is expecting a string value and would benefit from taking ownership of buffered data owned by the Deserializer. Read more
Source§

fn deserialize_bytes<V>( self, visitor: V, ) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where V: Visitor<'de>,

Hint that the Deserialize type is expecting a byte array and does not benefit from taking ownership of buffered data owned by the Deserializer. Read more
Source§

fn deserialize_byte_buf<V>( self, visitor: V, ) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where V: Visitor<'de>,

Hint that the Deserialize type is expecting a byte array and would benefit from taking ownership of buffered data owned by the Deserializer. Read more
Source§

fn deserialize_option<V>( self, visitor: V, ) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where V: Visitor<'de>,

Hint that the Deserialize type is expecting an optional value. Read more
Source§

fn deserialize_unit<V>( self, visitor: V, ) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where V: Visitor<'de>,

Hint that the Deserialize type is expecting a unit value.
Source§

fn deserialize_unit_struct<V>( self, name: &'static str, visitor: V, ) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where V: Visitor<'de>,

Hint that the Deserialize type is expecting a unit struct with a particular name.
Source§

fn deserialize_seq<V>( self, visitor: V, ) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where V: Visitor<'de>,

Hint that the Deserialize type is expecting a sequence of values.
Source§

fn deserialize_tuple<V>( self, len: usize, visitor: V, ) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where V: Visitor<'de>,

Hint that the Deserialize type is expecting a sequence of values and knows how many values there are without looking at the serialized data.
Source§

fn deserialize_tuple_struct<V>( self, name: &'static str, len: usize, visitor: V, ) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where V: Visitor<'de>,

Hint that the Deserialize type is expecting a tuple struct with a particular name and number of fields.
Source§

fn deserialize_map<V>( self, visitor: V, ) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where V: Visitor<'de>,

Hint that the Deserialize type is expecting a map of key-value pairs.
Source§

fn deserialize_struct<V>( self, name: &'static str, fields: &'static [&'static str], visitor: V, ) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where V: Visitor<'de>,

Hint that the Deserialize type is expecting a struct with a particular name and fields.
Source§

fn deserialize_identifier<V>( self, visitor: V, ) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where V: Visitor<'de>,

Hint that the Deserialize type is expecting the name of a struct field or the discriminant of an enum variant.
Source§

fn deserialize_ignored_any<V>( self, visitor: V, ) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where V: Visitor<'de>,

Hint that the Deserialize type needs to deserialize a value whose type doesn’t matter because it is ignored. Read more
Source§

fn is_human_readable(&self) -> bool

Determine whether Deserialize implementations should expect to deserialize their human-readable form. Read more
Source§

impl<K: Into<IString>, V: Into<IValue>> Extend<(K, V)> for IObject

Source§

fn extend<T: IntoIterator<Item = (K, V)>>(&mut self, iter: T)

Extends a collection with the contents of an iterator. Read more
Source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

impl<K: Into<IString>, V: Into<IValue>> From<BTreeMap<K, V>> for IObject

Source§

fn from(other: BTreeMap<K, V>) -> Self

Converts to this type from the input type.
Source§

impl<K: Into<IString>, V: Into<IValue>> From<HashMap<K, V>> for IObject

Source§

fn from(other: HashMap<K, V>) -> Self

Converts to this type from the input type.
Source§

impl From<IObject> for IValue

Source§

fn from(other: IObject) -> Self

Converts to this type from the input type.
Source§

impl<K: Into<IString>, V: Into<IValue>> FromIterator<(K, V)> for IObject

Source§

fn from_iter<T: IntoIterator<Item = (K, V)>>(iter: T) -> Self

Creates a value from an iterator. Read more
Source§

impl Hash for IObject

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<I: ObjectIndex> Index<I> for IObject

Source§

type Output = IValue

The returned type after indexing.
Source§

fn index(&self, index: I) -> &IValue

Performs the indexing (container[index]) operation. Read more
Source§

impl<I: ObjectIndex> IndexMut<I> for IObject

Source§

fn index_mut(&mut self, index: I) -> &mut IValue

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl<'a> IntoIterator for &'a IObject

Source§

type Item = (&'a IString, &'a IValue)

The type of the elements being iterated over.
Source§

type IntoIter = Iter<'a>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<'a> IntoIterator for &'a mut IObject

Source§

type Item = (&'a IString, &'a mut IValue)

The type of the elements being iterated over.
Source§

type IntoIter = IterMut<'a>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl IntoIterator for IObject

Source§

type Item = (IString, IValue)

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl PartialEq for IObject

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for IObject

Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Serialize for IObject

Source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl<'a> TryFrom<&'a IValue> for &'a IObject

Source§

type Error = ()

The type returned in the event of a conversion error.
Source§

fn try_from(other: &'a IValue) -> Result<Self, ()>

Performs the conversion.
Source§

impl<'a> TryFrom<&'a mut IValue> for &'a mut IObject

Source§

type Error = ()

The type returned in the event of a conversion error.
Source§

fn try_from(other: &'a mut IValue) -> Result<Self, ()>

Performs the conversion.
Source§

impl TryFrom<IValue> for IObject

Source§

type Error = IValue

The type returned in the event of a conversion error.
Source§

fn try_from(other: IValue) -> Result<Self, IValue>

Performs the conversion.
Source§

impl Eq for IObject

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

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