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
impl JsonObject
pub fn new() -> Self
pub fn from_vec(entries: Vec<(Key, JsonValue)>) -> Self
pub fn capacity(&self) -> usize
pub fn len(&self) -> usize
pub fn is_empty(&self) -> bool
pub fn get_fragment(&self, index: usize) -> Result<JsonFragment<'_>, usize>
pub fn entries(&self) -> &[Entry] ⓘ
pub fn iter(&self) -> Iter<'_>
pub fn iter_mut(&mut self) -> IterMut<'_>
pub fn iter_mapped<'m>( &self, code_map: &'m JsonCodeMap, offset: usize, ) -> IterMapped<'_, 'm> ⓘ
pub fn into_iter_mapped<'m>( self, code_map: &'m JsonCodeMap, offset: usize, ) -> IntoIterMapped<'m> ⓘ
pub fn iter_sorted(&self) -> IterSorted<'_>
pub fn iter_mut_sorted(&mut self) -> IterMutSorted<'_>
pub fn into_iter_sorted(self) -> IntoIterSorted
Sourcepub fn contains_key<Q>(&self, key: &Q) -> bool
pub fn contains_key<Q>(&self, key: &Q) -> bool
Checks if this object contains the given key.
Runs in O(log(n)) (average).
Sourcepub fn get<Q>(&self, key: &Q) -> Get<'_>
pub fn get<Q>(&self, key: &Q) -> Get<'_>
Returns an iterator over the values matching the given key.
Runs in O(log(n)) (average).
Sourcepub fn get_mut<Q>(&mut self, key: &Q) -> GetMut<'_>
pub fn get_mut<Q>(&mut self, key: &Q) -> GetMut<'_>
Returns an iterator over the values matching the given key.
Runs in O(log(n)) (average).
Sourcepub fn get_unique<Q>(
&self,
key: &Q,
) -> Result<Option<&JsonValue>, DuplicateEntry<EntryRef<'_>>>
pub fn get_unique<Q>( &self, key: &Q, ) -> Result<Option<&JsonValue>, DuplicateEntry<EntryRef<'_>>>
Returns the unique entry value matching the given key.
Returns an error if multiple entries match the key.
Runs in O(log(n)) (average).
Sourcepub fn get_unique_mut<Q>(
&mut self,
key: &Q,
) -> Result<Option<&mut JsonValue>, DuplicateEntry<EntryRef<'_>>>
pub fn get_unique_mut<Q>( &mut self, key: &Q, ) -> Result<Option<&mut JsonValue>, DuplicateEntry<EntryRef<'_>>>
Returns the unique entry value matching the given key.
Returns an error if multiple entries match the key.
Runs in O(log(n)) (average).
Sourcepub fn get_entries<Q>(&self, key: &Q) -> GetEntries<'_>
pub fn get_entries<Q>(&self, key: &Q) -> GetEntries<'_>
Returns an iterator over the entries matching the given key.
Runs in O(log(n)) (average).
Sourcepub fn get_unique_entry<Q>(
&self,
key: &Q,
) -> Result<Option<EntryRef<'_>>, DuplicateEntry<EntryRef<'_>>>
pub fn get_unique_entry<Q>( &self, key: &Q, ) -> Result<Option<EntryRef<'_>>, DuplicateEntry<EntryRef<'_>>>
Returns the unique entry matching the given key.
Returns an error if multiple entries match the key.
Runs in O(log(n)) (average).
Sourcepub fn get_indexed<Q>(&self, key: &Q) -> GetIndexed<'_>
pub fn get_indexed<Q>(&self, key: &Q) -> GetIndexed<'_>
Returns an iterator over the values matching the given key.
Runs in O(log(n)) (average).
Sourcepub fn get_indexed_entries<Q>(&self, key: &Q) -> GetIndexedEntries<'_>
pub fn get_indexed_entries<Q>(&self, key: &Q) -> GetIndexedEntries<'_>
Returns an iterator over the entries matching the given key.
Runs in O(log(n)) (average).
Sourcepub fn get_or_insert_with<Q>(
&mut self,
key: impl Into<Key>,
f: impl FnOnce() -> JsonValue,
) -> Get<'_>
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.
Sourcepub fn get_or_insert_mut_with<Q>(
&mut self,
key: impl Into<Key>,
f: impl FnOnce() -> JsonValue,
) -> GetMut<'_>
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.
pub fn index_of<Q>(&self, key: &Q) -> Option<usize>
pub fn indexes_of<Q>(&self, key: &Q) -> IndexesIter<'_> ⓘ
pub fn redundant_index_of<Q>(&self, key: &Q) -> Option<usize>
Sourcepub fn get_mapped_entries<'m, Q>(
&self,
code_map: &'m JsonCodeMap,
offset: usize,
key: &Q,
) -> GetMappedEntries<'_, 'm> ⓘ
pub fn get_mapped_entries<'m, Q>( &self, code_map: &'m JsonCodeMap, offset: usize, key: &Q, ) -> GetMappedEntries<'_, 'm> ⓘ
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.
Sourcepub fn get_unique_mapped_entry<Q>(
&self,
code_map: &JsonCodeMap,
offset: usize,
key: &Q,
) -> Result<Option<MappedEntryRef<'_>>, DuplicateEntry<MappedEntryRef<'_>>>
pub fn get_unique_mapped_entry<Q>( &self, code_map: &JsonCodeMap, offset: usize, key: &Q, ) -> Result<Option<MappedEntryRef<'_>>, DuplicateEntry<MappedEntryRef<'_>>>
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.
Sourcepub fn get_mapped_entries_with_index<'m, Q>(
&self,
code_map: &'m JsonCodeMap,
offset: usize,
key: &Q,
) -> GetIndexedMappedEntries<'_, 'm> ⓘ
pub fn get_mapped_entries_with_index<'m, Q>( &self, code_map: &'m JsonCodeMap, offset: usize, key: &Q, ) -> GetIndexedMappedEntries<'_, 'm> ⓘ
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.
Sourcepub fn get_unique_mapped_entry_with_index<Q>(
&self,
code_map: &JsonCodeMap,
offset: usize,
key: &Q,
) -> Result<Option<IndexedMappedEntry<'_>>, DuplicateEntry<IndexedMappedEntry<'_>>>
pub fn get_unique_mapped_entry_with_index<Q>( &self, code_map: &JsonCodeMap, offset: usize, key: &Q, ) -> Result<Option<IndexedMappedEntry<'_>>, DuplicateEntry<IndexedMappedEntry<'_>>>
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.
Sourcepub fn get_mapped<'m, Q>(
&self,
code_map: &'m JsonCodeMap,
offset: usize,
key: &Q,
) -> GetMapped<'_, 'm> ⓘ
pub fn get_mapped<'m, Q>( &self, code_map: &'m JsonCodeMap, offset: usize, key: &Q, ) -> GetMapped<'_, 'm> ⓘ
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.
Sourcepub fn get_unique_mapped<Q>(
&self,
code_map: &JsonCodeMap,
offset: usize,
key: &Q,
) -> Result<Option<JsonMapped<&JsonValue>>, DuplicateEntry<JsonMapped<&JsonValue>>>
pub fn get_unique_mapped<Q>( &self, code_map: &JsonCodeMap, offset: usize, key: &Q, ) -> Result<Option<JsonMapped<&JsonValue>>, DuplicateEntry<JsonMapped<&JsonValue>>>
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.
Sourcepub fn get_indexed_mapped<'m, Q>(
&self,
code_map: &'m JsonCodeMap,
offset: usize,
key: &Q,
) -> GetIndexedMapped<'_, 'm> ⓘ
pub fn get_indexed_mapped<'m, Q>( &self, code_map: &'m JsonCodeMap, offset: usize, key: &Q, ) -> GetIndexedMapped<'_, 'm> ⓘ
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.
Sourcepub fn get_unique_mapped_with_index<Q>(
&self,
code_map: &JsonCodeMap,
offset: usize,
key: &Q,
) -> Result<Option<IndexedMappedValue<'_>>, DuplicateEntry<IndexedMappedValue<'_>>>
pub fn get_unique_mapped_with_index<Q>( &self, code_map: &JsonCodeMap, offset: usize, key: &Q, ) -> Result<Option<IndexedMappedValue<'_>>, DuplicateEntry<IndexedMappedValue<'_>>>
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.
pub fn first(&self) -> Option<EntryRef<'_>>
pub fn last(&self) -> Option<EntryRef<'_>>
Sourcepub fn push_back(
&mut self,
key: impl Into<Key>,
value: JsonValue,
) -> (usize, bool)
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).
pub fn push_entry_back(&mut self, (key, value): Entry) -> (usize, bool)
Sourcepub fn push_front(&mut self, key: impl Into<Key>, value: JsonValue) -> bool
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).
pub fn push_entry_front(&mut self, (key, value): Entry) -> bool
Sourcepub fn swap_remove_at(&mut self, i: usize) -> Option<Entry>
pub fn swap_remove_at(&mut self, i: usize) -> Option<Entry>
Removes the entry at the given index i.
Sourcepub fn shift_remove_at(&mut self, i: usize) -> Option<Entry>
pub fn shift_remove_at(&mut self, i: usize) -> Option<Entry>
Removes the entry at the given index i.
Sourcepub fn shift_insert(
&mut self,
key: impl Into<Key>,
value: JsonValue,
) -> ShiftInsert<'_>
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.
pub fn swap_insert( &mut self, key: impl Into<Key>, value: JsonValue, ) -> SwapInsert<'_>
Sourcepub fn shift_insert_front(
&mut self,
key: impl Into<Key>,
value: JsonValue,
) -> ShiftInsertFront<'_>
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.
pub fn swap_insert_front( &mut self, key: impl Into<Key>, value: JsonValue, ) -> SwapInsertFront<'_>
pub fn shift_insert_back_full( &mut self, key: impl Into<Key>, value: JsonValue, ) -> (usize, ShiftInsertBack<'_>)
pub fn shift_insert_back( &mut self, key: impl Into<Key>, value: JsonValue, ) -> ShiftInsertBack<'_>
Sourcepub fn insert(
&mut self,
key: impl Into<Key>,
value: JsonValue,
) -> ShiftInsertBack<'_>
pub fn insert( &mut self, key: impl Into<Key>, value: JsonValue, ) -> ShiftInsertBack<'_>
Alias of Self::shift_insert_back.
pub fn swap_insert_back_full( &mut self, key: impl Into<Key>, value: JsonValue, ) -> (usize, SwapInsertBack<'_>)
pub fn swap_insert_back( &mut self, key: impl Into<Key>, value: JsonValue, ) -> SwapInsertBack<'_>
pub fn shift_remove_indexed_entries<Q>( &mut self, key: &Q, ) -> ShiftRemoveIndexedEntries<'_>
Sourcepub fn shift_remove_entries<Q>(&mut self, key: &Q) -> ShiftRemoveEntries<'_>
pub fn shift_remove_entries<Q>(&mut self, key: &Q) -> ShiftRemoveEntries<'_>
Remove all entries associated to the given key.
Sourcepub fn shift_remove<Q>(&mut self, key: &Q) -> ShiftRemove<'_>
pub fn shift_remove<Q>(&mut self, key: &Q) -> ShiftRemove<'_>
Remove all entries associated to the given key.
Sourcepub fn remove<Q>(&mut self, key: &Q) -> ShiftRemove<'_>
pub fn remove<Q>(&mut self, key: &Q) -> ShiftRemove<'_>
Alias of Self::shift_remove.
Sourcepub fn remove_unique<Q>(
&mut self,
key: &Q,
) -> Result<Option<Entry>, DuplicateEntry<Entry>>
pub fn remove_unique<Q>( &mut self, key: &Q, ) -> Result<Option<Entry>, DuplicateEntry<Entry>>
Alias of Self::shift_remove_unique.
pub fn swap_remove_indexed_entries<Q>( &mut self, key: &Q, ) -> SwapRemoveIndexedEntries<'_>
pub fn swap_remove_entries<Q>(&mut self, key: &Q) -> SwapRemoveEntries<'_>
pub fn swap_remove<Q>(&mut self, key: &Q) -> SwapRemove<'_>
Sourcepub fn swap_remove_unique<Q>(
&mut self,
key: &Q,
) -> Result<Option<Entry>, DuplicateEntry<Entry>>
pub fn swap_remove_unique<Q>( &mut self, key: &Q, ) -> Result<Option<Entry>, DuplicateEntry<Entry>>
Remove the unique entry associated to the given key.
Returns an error if multiple entries match the key.
Sourcepub fn shift_remove_unique<Q>(
&mut self,
key: &Q,
) -> Result<Option<Entry>, DuplicateEntry<Entry>>
pub fn shift_remove_unique<Q>( &mut self, key: &Q, ) -> Result<Option<Entry>, DuplicateEntry<Entry>>
Remove the unique entry associated to the given key.
Returns an error if multiple entries match the key.
Sourcepub fn sort(&mut self)
pub fn sort(&mut self)
Sort the entries by key name.
The relative order of entries with the same key is unchanged.
Sourcepub fn canonicalize_with(&mut self, buffer: &mut Buffer)
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.
Sourcepub fn canonicalize(&mut self)
pub fn canonicalize(&mut self)
Puts this JSON object in canonical form according to RFC 8785.
Trait Implementations§
Source§impl Clone for JsonObject
impl Clone for JsonObject
Source§impl Debug for JsonObject
impl Debug for JsonObject
Source§impl Default for JsonObject
impl Default for JsonObject
Source§impl<'de> Deserialize<'de> for JsonObject
impl<'de> Deserialize<'de> for JsonObject
Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
impl Eq for JsonObject
Source§impl Extend<(SmallString<[u8; 16]>, JsonValue)> for JsonObject
impl Extend<(SmallString<[u8; 16]>, JsonValue)> for JsonObject
Source§fn extend<I: IntoIterator<Item = Entry>>(&mut self, iter: I)
fn extend<I: IntoIterator<Item = Entry>>(&mut self, iter: I)
Source§fn extend_one(&mut self, item: T)
fn extend_one(&mut self, item: T)
extend_one)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one)Source§impl From<JsonObject> for JsonValue
impl From<JsonObject> for JsonValue
Source§fn from(o: JsonObject) -> Self
fn from(o: JsonObject) -> Self
Source§impl From<Vec<(SmallString<[u8; 16]>, JsonValue)>> for JsonObject
impl From<Vec<(SmallString<[u8; 16]>, JsonValue)>> for JsonObject
Source§impl FromIterator<(SmallString<[u8; 16]>, JsonValue)> for JsonObject
impl FromIterator<(SmallString<[u8; 16]>, JsonValue)> for JsonObject
Source§impl Hash for JsonObject
impl Hash for JsonObject
Source§impl<'de> IntoDeserializer<'de, DeserializeError> for JsonObject
impl<'de> IntoDeserializer<'de, DeserializeError> for JsonObject
Source§type Deserializer = JsonValue
type Deserializer = JsonValue
Source§fn into_deserializer(self) -> Self::Deserializer
fn into_deserializer(self) -> Self::Deserializer
Source§impl<'a> IntoIterator for &'a JsonObject
impl<'a> IntoIterator for &'a JsonObject
Source§impl<'a> IntoIterator for &'a mut JsonObject
impl<'a> IntoIterator for &'a mut JsonObject
Source§impl IntoIterator for JsonObject
impl IntoIterator for JsonObject
Source§impl JsonBorrowLexical for JsonObject
impl JsonBorrowLexical for JsonObject
fn as_lexical(&self) -> &JsonLexical<Self>
impl JsonLexicalEq for JsonObject
Source§impl JsonLexicalHash for JsonObject
impl JsonLexicalHash for JsonObject
fn lexical_hash<H: Hasher>(&self, state: &mut H)
Source§impl JsonLexicalPartialEq for JsonObject
impl JsonLexicalPartialEq for JsonObject
fn lexical_eq(&self, other: &Self) -> bool
Source§impl JsonVisit for JsonObject
impl JsonVisit for JsonObject
fn visit<V: JsonVisitor>(&self, visitor: V) -> V::Output
Source§impl Ord for JsonObject
impl Ord for JsonObject
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
1.21.0 (const: unstable) · Source§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialEq for JsonObject
impl PartialEq for JsonObject
Source§impl PartialOrd for JsonObject
impl PartialOrd for JsonObject
Source§impl Serialize for JsonObject
impl Serialize for JsonObject
impl StructuralPartialEq for JsonObject
Auto Trait Implementations§
impl Freeze for JsonObject
impl RefUnwindSafe for JsonObject
impl Send for JsonObject
impl Sync for JsonObject
impl Unpin for JsonObject
impl UnsafeUnpin for JsonObject
impl UnwindSafe for JsonObject
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> JsonPrint for Twhere
T: JsonVisit,
impl<T> JsonPrint for Twhere
T: JsonVisit,
fn fmt_with( &self, f: &mut Formatter<'_>, options: &JsonPrintOptions, indent: usize, ) -> Result<(), Error>
Source§fn pretty_print(&self) -> Printed<'_, 'static, Self>
fn pretty_print(&self) -> Printed<'_, 'static, Self>
Options::pretty options.Source§fn compact_print(&self) -> Printed<'_, 'static, Self>
fn compact_print(&self) -> Printed<'_, 'static, Self>
Options::compact options.Source§fn inline_print(&self) -> Printed<'_, 'static, Self>
fn inline_print(&self) -> Printed<'_, 'static, Self>
Options::inline options.