Skip to main content

JsonObject

Struct JsonObject 

Source
pub struct JsonObject { /* private fields */ }
Expand description

JSON object.

§Comparison

The PartialEq and PartialOrd implementations will compare the JSON objects semantically, without regard for the entries indexes. The only exception is when one key has multiple values, in which cases the values are ordered by index. It is possible to compare the lexical representation of objects (where the entries indexes matter) by using the [BorrowJsonLexical::as_lexical] method on both ends and comparing the results.

Implementations§

Source§

impl JsonObject

Source

pub fn new() -> Self

Source

pub fn from_vec(entries: Vec<(Key, JsonValue)>) -> Self

Source

pub fn capacity(&self) -> usize

Source

pub fn len(&self) -> usize

Source

pub fn is_empty(&self) -> bool

Source

pub fn get_fragment(&self, index: usize) -> Result<JsonFragment<'_>, usize>

Source

pub fn entries(&self) -> &[Entry] ⓘ

Source

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

Source

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

Source

pub fn iter_mapped<'m>( &self, code_map: &'m JsonCodeMap, offset: usize, ) -> IterMapped<'_, 'm> ⓘ

Source

pub fn into_iter_mapped<'m>( self, code_map: &'m JsonCodeMap, offset: usize, ) -> IntoIterMapped<'m> ⓘ

Source

pub fn iter_sorted(&self) -> IterSorted<'_>

Source

pub fn iter_mut_sorted(&mut self) -> IterMutSorted<'_>

Source

pub fn into_iter_sorted(self) -> IntoIterSorted

Source

pub fn contains_key<Q>(&self, key: &Q) -> bool
where Q: ?Sized + Comparable<Key>,

Checks if this object contains the given key.

Runs in O(log(n)) (average).

Source

pub fn get<Q>(&self, key: &Q) -> Get<'_>
where Q: ?Sized + Comparable<Key>,

Returns an iterator over the values matching the given key.

Runs in O(log(n)) (average).

Source

pub fn get_mut<Q>(&mut self, key: &Q) -> GetMut<'_>
where Q: ?Sized + Comparable<Key>,

Returns an iterator over the values matching the given key.

Runs in O(log(n)) (average).

Source

pub fn get_unique<Q>( &self, key: &Q, ) -> Result<Option<&JsonValue>, DuplicateEntry<EntryRef<'_>>>
where Q: ?Sized + Comparable<Key>,

Returns the unique entry value matching the given key.

Returns an error if multiple entries match the key.

Runs in O(log(n)) (average).

Source

pub fn get_unique_mut<Q>( &mut self, key: &Q, ) -> Result<Option<&mut JsonValue>, DuplicateEntry<EntryRef<'_>>>
where Q: ?Sized + Comparable<Key>,

Returns the unique entry value matching the given key.

Returns an error if multiple entries match the key.

Runs in O(log(n)) (average).

Source

pub fn get_entries<Q>(&self, key: &Q) -> GetEntries<'_>
where Q: ?Sized + Comparable<Key>,

Returns an iterator over the entries matching the given key.

Runs in O(log(n)) (average).

Source

pub fn get_unique_entry<Q>( &self, key: &Q, ) -> Result<Option<EntryRef<'_>>, DuplicateEntry<EntryRef<'_>>>
where Q: ?Sized + Comparable<Key>,

Returns the unique entry matching the given key.

Returns an error if multiple entries match the key.

Runs in O(log(n)) (average).

Source

pub fn get_indexed<Q>(&self, key: &Q) -> GetIndexed<'_>
where Q: ?Sized + Comparable<Key>,

Returns an iterator over the values matching the given key.

Runs in O(log(n)) (average).

Source

pub fn get_indexed_entries<Q>(&self, key: &Q) -> GetIndexedEntries<'_>
where Q: ?Sized + Comparable<Key>,

Returns an iterator over the entries matching the given key.

Runs in O(log(n)) (average).

Source

pub fn get_or_insert_with<Q>( &mut self, key: impl Into<Key>, f: impl FnOnce() -> JsonValue, ) -> Get<'_>

Returns the (first) value associated to key, or insert a key-value entry where value is returned by the given function f.

Source

pub fn get_or_insert_mut_with<Q>( &mut self, key: impl Into<Key>, f: impl FnOnce() -> JsonValue, ) -> GetMut<'_>

Returns a mutable reference to the (first) value associated to key, or insert a key-value entry where value is returned by the given function f.

Source

pub fn index_of<Q>(&self, key: &Q) -> Option<usize>
where Q: ?Sized + Comparable<Key>,

Source

pub fn indexes_of<Q>(&self, key: &Q) -> IndexesIter<'_> ⓘ
where Q: ?Sized + Comparable<Key>,

Source

pub fn redundant_index_of<Q>(&self, key: &Q) -> Option<usize>
where Q: ?Sized + Comparable<Key>,

Source

pub fn get_mapped_entries<'m, Q>( &self, code_map: &'m JsonCodeMap, offset: usize, key: &Q, ) -> GetMappedEntries<'_, 'm> ⓘ
where Q: ?Sized + Comparable<Key>,

Returns an iterator over the mapped entries matching the given key.

Runs in O(n) (average). O(log(n)) to find the entry, O(n) to compute the entry fragment offset.

Source

pub fn get_unique_mapped_entry<Q>( &self, code_map: &JsonCodeMap, offset: usize, key: &Q, ) -> Result<Option<MappedEntryRef<'_>>, DuplicateEntry<MappedEntryRef<'_>>>
where Q: ?Sized + Comparable<Key>,

Returns the unique mapped entry matching the given key.

Runs in O(n) (average). O(1) to find the entry, O(n) to compute the entry fragment offset.

Source

pub fn get_mapped_entries_with_index<'m, Q>( &self, code_map: &'m JsonCodeMap, offset: usize, key: &Q, ) -> GetIndexedMappedEntries<'_, 'm> ⓘ
where Q: ?Sized + Comparable<Key>,

Returns an iterator over the mapped entries matching the given key, with their index.

Runs in O(n) (average). O(1) to find the entry, O(n) to compute the entry fragment offset.

Source

pub fn get_unique_mapped_entry_with_index<Q>( &self, code_map: &JsonCodeMap, offset: usize, key: &Q, ) -> Result<Option<IndexedMappedEntry<'_>>, DuplicateEntry<IndexedMappedEntry<'_>>>
where Q: ?Sized + Comparable<Key>,

Returns the unique mapped entry matching the given key, with its index.

Runs in O(n) (average). O(1) to find the entry, O(n) to compute the entry fragment offset.

Source

pub fn get_mapped<'m, Q>( &self, code_map: &'m JsonCodeMap, offset: usize, key: &Q, ) -> GetMapped<'_, 'm> ⓘ
where Q: ?Sized + Comparable<Key>,

Returns an iterator over the mapped values matching the given key.

Runs in O(n) (average). O(1) to find the entry, O(n) to compute the entry fragment offset.

Source

pub fn get_unique_mapped<Q>( &self, code_map: &JsonCodeMap, offset: usize, key: &Q, ) -> Result<Option<JsonMapped<&JsonValue>>, DuplicateEntry<JsonMapped<&JsonValue>>>
where Q: ?Sized + Comparable<Key>,

Returns the unique mapped values matching the given key.

Runs in O(n) (average). O(1) to find the entry, O(n) to compute the entry fragment offset.

Source

pub fn get_indexed_mapped<'m, Q>( &self, code_map: &'m JsonCodeMap, offset: usize, key: &Q, ) -> GetIndexedMapped<'_, 'm> ⓘ
where Q: ?Sized + Comparable<Key>,

Returns an iterator over the mapped values matching the given key, with their index.

Runs in O(n) (average). O(1) to find the entry, O(n) to compute the entry fragment offset.

Source

pub fn get_unique_mapped_with_index<Q>( &self, code_map: &JsonCodeMap, offset: usize, key: &Q, ) -> Result<Option<IndexedMappedValue<'_>>, DuplicateEntry<IndexedMappedValue<'_>>>
where Q: ?Sized + Comparable<Key>,

Returns the unique mapped values matching the given key, with its index.

Runs in O(n) (average). O(1) to find the entry, O(n) to compute the entry fragment offset.

Source

pub fn first(&self) -> Option<EntryRef<'_>>

Source

pub fn last(&self) -> Option<EntryRef<'_>>

Source

pub fn push_back( &mut self, key: impl Into<Key>, value: JsonValue, ) -> (usize, bool)

Push the given key-value pair to the end of the object.

Returns true if the key was not already present in the object, and false otherwise. Any previous entry matching the key is not overridden: duplicates are preserved, in order.

Runs in O(1).

Source

pub fn push_entry_back(&mut self, (key, value): Entry) -> (usize, bool)

Source

pub fn push_front(&mut self, key: impl Into<Key>, value: JsonValue) -> bool

Push the given key-value pair to the top of the object.

Returns true if the key was not already present in the object, and false otherwise. Any previous entry matching the key is not overridden: duplicates are preserved, in order.

Runs in O(n).

Source

pub fn push_entry_front(&mut self, (key, value): Entry) -> bool

Source

pub fn swap_remove_at(&mut self, i: usize) -> Option<Entry>

Removes the entry at the given index i.

Source

pub fn shift_remove_at(&mut self, i: usize) -> Option<Entry>

Removes the entry at the given index i.

Source

pub fn shift_insert( &mut self, key: impl Into<Key>, value: JsonValue, ) -> ShiftInsert<'_>

Inserts the given key-value pair.

If one or more entries are already matching the given key, all of them are removed and returned in the resulting iterator. Otherwise, None is returned.

Source

pub fn swap_insert( &mut self, key: impl Into<Key>, value: JsonValue, ) -> SwapInsert<'_>

Source

pub fn shift_insert_front( &mut self, key: impl Into<Key>, value: JsonValue, ) -> ShiftInsertFront<'_>

Inserts the given key-value pair on top of the object.

If one or more entries are already matching the given key, all of them are removed and returned in the resulting iterator.

Source

pub fn swap_insert_front( &mut self, key: impl Into<Key>, value: JsonValue, ) -> SwapInsertFront<'_>

Source

pub fn shift_insert_back_full( &mut self, key: impl Into<Key>, value: JsonValue, ) -> (usize, ShiftInsertBack<'_>)

Source

pub fn shift_insert_back( &mut self, key: impl Into<Key>, value: JsonValue, ) -> ShiftInsertBack<'_>

Source

pub fn insert( &mut self, key: impl Into<Key>, value: JsonValue, ) -> ShiftInsertBack<'_>

Source

pub fn swap_insert_back_full( &mut self, key: impl Into<Key>, value: JsonValue, ) -> (usize, SwapInsertBack<'_>)

Source

pub fn swap_insert_back( &mut self, key: impl Into<Key>, value: JsonValue, ) -> SwapInsertBack<'_>

Source

pub fn shift_remove_indexed_entries<Q>( &mut self, key: &Q, ) -> ShiftRemoveIndexedEntries<'_>
where Q: ?Sized + Comparable<Key>,

Source

pub fn shift_remove_entries<Q>(&mut self, key: &Q) -> ShiftRemoveEntries<'_>
where Q: ?Sized + Comparable<Key>,

Remove all entries associated to the given key.

Source

pub fn shift_remove<Q>(&mut self, key: &Q) -> ShiftRemove<'_>
where Q: ?Sized + Comparable<Key>,

Remove all entries associated to the given key.

Source

pub fn remove<Q>(&mut self, key: &Q) -> ShiftRemove<'_>
where Q: ?Sized + Comparable<Key>,

Source

pub fn remove_unique<Q>( &mut self, key: &Q, ) -> Result<Option<Entry>, DuplicateEntry<Entry>>
where Q: ?Sized + Comparable<Key>,

Source

pub fn swap_remove_indexed_entries<Q>( &mut self, key: &Q, ) -> SwapRemoveIndexedEntries<'_>
where Q: ?Sized + Comparable<Key>,

Source

pub fn swap_remove_entries<Q>(&mut self, key: &Q) -> SwapRemoveEntries<'_>
where Q: ?Sized + Comparable<Key>,

Source

pub fn swap_remove<Q>(&mut self, key: &Q) -> SwapRemove<'_>
where Q: ?Sized + Comparable<Key>,

Source

pub fn swap_remove_unique<Q>( &mut self, key: &Q, ) -> Result<Option<Entry>, DuplicateEntry<Entry>>
where Q: ?Sized + Comparable<Key>,

Remove the unique entry associated to the given key.

Returns an error if multiple entries match the key.

Source

pub fn shift_remove_unique<Q>( &mut self, key: &Q, ) -> Result<Option<Entry>, DuplicateEntry<Entry>>
where Q: ?Sized + Comparable<Key>,

Remove the unique entry associated to the given key.

Returns an error if multiple entries match the key.

Source

pub fn sort(&mut self)

Sort the entries by key name.

The relative order of entries with the same key is unchanged.

Source

pub fn canonicalize_with(&mut self, buffer: &mut Buffer)

Puts this JSON object in canonical form according to RFC 8785.

This will canonicalize the entries and sort them by key. The relative order of entries with the same key is unchanged.

Source

pub fn canonicalize(&mut self)

Puts this JSON object in canonical form according to RFC 8785.

Trait Implementations§

Source§

impl Clone for JsonObject

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for JsonObject

Source§

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

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

impl Default for JsonObject

Source§

fn default() -> Self

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

impl<'de> Deserialize<'de> for JsonObject

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 Eq for JsonObject

Source§

impl Extend<(SmallString<[u8; 16]>, JsonValue)> for JsonObject

Source§

fn extend<I: IntoIterator<Item = Entry>>(&mut self, iter: I)

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

fn extend_one(&mut self, item: T)

🔬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 From<JsonObject> for JsonValue

Source§

fn from(o: JsonObject) -> Self

Converts to this type from the input type.
Source§

impl From<Vec<(SmallString<[u8; 16]>, JsonValue)>> for JsonObject

Source§

fn from(entries: Vec<Entry>) -> Self

Converts to this type from the input type.
Source§

impl FromIterator<(SmallString<[u8; 16]>, JsonValue)> for JsonObject

Source§

fn from_iter<I: IntoIterator<Item = Entry>>(iter: I) -> Self

Creates a value from an iterator. Read more
Source§

impl Hash for JsonObject

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<'de> IntoDeserializer<'de, DeserializeError> for JsonObject

Source§

type Deserializer = JsonValue

The type of the deserializer being converted into.
Source§

fn into_deserializer(self) -> Self::Deserializer

Convert this value into a deserializer.
Source§

impl<'a> IntoIterator for &'a JsonObject

Source§

type Item = (&'a SmallString<[u8; 16]>, &'a JsonValue)

The type of the elements being iterated over.
Source§

type IntoIter = Iter<'a, SmallString<[u8; 16]>, JsonValue>

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 JsonObject

Source§

type Item = (&'a SmallString<[u8; 16]>, &'a mut JsonValue)

The type of the elements being iterated over.
Source§

type IntoIter = IterMut<'a, SmallString<[u8; 16]>, JsonValue>

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 JsonObject

Source§

type Item = (SmallString<[u8; 16]>, JsonValue)

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<(SmallString<[u8; 16]>, JsonValue)>

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 JsonBorrowLexical for JsonObject

Source§

fn as_lexical(&self) -> &JsonLexical<Self>

Source§

impl JsonLexicalEq for JsonObject

Source§

impl JsonLexicalHash for JsonObject

Source§

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

Source§

impl JsonLexicalPartialEq for JsonObject

Source§

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

Source§

impl JsonVisit for JsonObject

Source§

fn visit<V: JsonVisitor>(&self, visitor: V) -> V::Output

Source§

impl Ord for JsonObject

Source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

fn clamp_to<R>(self, range: R) -> Self
where Self: Sized, R: ClampBounds<Self>,

🔬This is a nightly-only experimental API. (clamp_to)
Restrict a value to a certain range. Read more
Source§

impl PartialEq for JsonObject

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl PartialOrd for JsonObject

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 (const: unstable) · 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 (const: unstable) · 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 (const: unstable) · 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 (const: unstable) · 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 JsonObject

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 StructuralPartialEq for JsonObject

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> Comparable<K> for Q
where Q: Ord + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn compare(&self, key: &K) -> Ordering

Compare self to key and return their ordering.
Source§

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

Source§

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

Source§

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

Compare self to key and return true if they are equal.
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> JsonPrint for T
where T: JsonVisit,

Source§

fn fmt_with( &self, f: &mut Formatter<'_>, options: &JsonPrintOptions, indent: usize, ) -> Result<(), Error>

Source§

fn pretty_print(&self) -> Printed<'_, 'static, Self>

Print the value with Options::pretty options.
Source§

fn compact_print(&self) -> Printed<'_, 'static, Self>

Print the value with Options::compact options.
Source§

fn inline_print(&self) -> Printed<'_, 'static, Self>

Print the value with Options::inline options.
Source§

fn print_with<'o>(&self, options: &'o JsonPrintOptions) -> Printed<'_, 'o, Self>

Print the value with the given options.
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 = !

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

fn try_from(value: U) -> Result<T, !>

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.