Struct json_syntax::object::Object
source · pub struct Object { /* private fields */ }
Expand description
Object.
Implementations§
source§impl Object
impl Object
pub fn new() -> Self
pub fn from_vec(entries: Vec<Entry>) -> 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<FragmentRef<'_>, 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 CodeMap, offset: usize, ) -> IterMapped<'_, 'm> ⓘ
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(1)
(average).
sourcepub fn get<Q>(&self, key: &Q) -> Values<'_> ⓘ
pub fn get<Q>(&self, key: &Q) -> Values<'_> ⓘ
Returns an iterator over the values matching the given key.
Runs in O(1)
(average).
sourcepub fn get_mut<Q>(&mut self, key: &Q) -> ValuesMut<'_> ⓘ
pub fn get_mut<Q>(&mut self, key: &Q) -> ValuesMut<'_> ⓘ
Returns an iterator over the values matching the given key.
Runs in O(1)
(average).
sourcepub fn get_unique<Q>(
&self,
key: &Q,
) -> Result<Option<&Value>, Duplicate<&Entry>>
pub fn get_unique<Q>( &self, key: &Q, ) -> Result<Option<&Value>, Duplicate<&Entry>>
Returns the unique entry value matching the given key.
Returns an error if multiple entries match the key.
Runs in O(1)
(average).
sourcepub fn get_unique_mut<Q>(
&mut self,
key: &Q,
) -> Result<Option<&mut Value>, Duplicate<&Entry>>
pub fn get_unique_mut<Q>( &mut self, key: &Q, ) -> Result<Option<&mut Value>, Duplicate<&Entry>>
Returns the unique entry value matching the given key.
Returns an error if multiple entries match the key.
Runs in O(1)
(average).
sourcepub fn get_entries<Q>(&self, key: &Q) -> Entries<'_> ⓘ
pub fn get_entries<Q>(&self, key: &Q) -> Entries<'_> ⓘ
Returns an iterator over the entries matching the given key.
Runs in O(1)
(average).
sourcepub fn get_unique_entry<Q>(
&self,
key: &Q,
) -> Result<Option<&Entry>, Duplicate<&Entry>>
pub fn get_unique_entry<Q>( &self, key: &Q, ) -> Result<Option<&Entry>, Duplicate<&Entry>>
Returns the unique entry matching the given key.
Returns an error if multiple entries match the key.
Runs in O(1)
(average).
sourcepub fn get_with_index<Q>(&self, key: &Q) -> ValuesWithIndex<'_> ⓘ
pub fn get_with_index<Q>(&self, key: &Q) -> ValuesWithIndex<'_> ⓘ
Returns an iterator over the values matching the given key.
Runs in O(1)
(average).
sourcepub fn get_entries_with_index<Q>(&self, key: &Q) -> EntriesWithIndex<'_> ⓘ
pub fn get_entries_with_index<Q>(&self, key: &Q) -> EntriesWithIndex<'_> ⓘ
Returns an iterator over the entries matching the given key.
Runs in O(1)
(average).
sourcepub fn get_or_insert_with<Q>(
&mut self,
key: &Q,
f: impl FnOnce() -> Value,
) -> &Value
pub fn get_or_insert_with<Q>( &mut self, key: &Q, f: impl FnOnce() -> Value, ) -> &Value
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_mut_or_insert_with<Q>(
&mut self,
key: &Q,
f: impl FnOnce() -> Value,
) -> &mut Value
pub fn get_mut_or_insert_with<Q>( &mut self, key: &Q, f: impl FnOnce() -> Value, ) -> &mut Value
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 redundant_index_of<Q>(&self, key: &Q) -> Option<usize>
pub fn indexes_of<Q>(&self, key: &Q) -> Indexes<'_> ⓘ
sourcepub fn get_mapped_entries<'m, Q>(
&self,
code_map: &'m CodeMap,
offset: usize,
key: &Q,
) -> MappedEntries<'_, 'm> ⓘ
pub fn get_mapped_entries<'m, Q>( &self, code_map: &'m CodeMap, offset: usize, key: &Q, ) -> MappedEntries<'_, 'm> ⓘ
Returns an iterator over the mapped entries 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_entry<Q>(
&self,
code_map: &CodeMap,
offset: usize,
key: &Q,
) -> Result<Option<MappedEntry<'_>>, Duplicate<MappedEntry<'_>>>
pub fn get_unique_mapped_entry<Q>( &self, code_map: &CodeMap, offset: usize, key: &Q, ) -> Result<Option<MappedEntry<'_>>, Duplicate<MappedEntry<'_>>>
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 CodeMap,
offset: usize,
key: &Q,
) -> MappedEntriesWithIndex<'_, 'm> ⓘ
pub fn get_mapped_entries_with_index<'m, Q>( &self, code_map: &'m CodeMap, offset: usize, key: &Q, ) -> MappedEntriesWithIndex<'_, '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: &CodeMap,
offset: usize,
key: &Q,
) -> Result<Option<IndexedMappedEntry<'_>>, Duplicate<IndexedMappedEntry<'_>>>
pub fn get_unique_mapped_entry_with_index<Q>( &self, code_map: &CodeMap, offset: usize, key: &Q, ) -> Result<Option<IndexedMappedEntry<'_>>, Duplicate<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 CodeMap,
offset: usize,
key: &Q,
) -> MappedValues<'_, 'm> ⓘ
pub fn get_mapped<'m, Q>( &self, code_map: &'m CodeMap, offset: usize, key: &Q, ) -> MappedValues<'_, '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: &CodeMap,
offset: usize,
key: &Q,
) -> Result<Option<Mapped<&Value>>, Duplicate<Mapped<&Value>>>
pub fn get_unique_mapped<Q>( &self, code_map: &CodeMap, offset: usize, key: &Q, ) -> Result<Option<Mapped<&Value>>, Duplicate<Mapped<&Value>>>
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_mapped_with_index<'m, Q>(
&self,
code_map: &'m CodeMap,
offset: usize,
key: &Q,
) -> MappedValuesWithIndex<'_, 'm> ⓘ
pub fn get_mapped_with_index<'m, Q>( &self, code_map: &'m CodeMap, offset: usize, key: &Q, ) -> MappedValuesWithIndex<'_, '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: &CodeMap,
offset: usize,
key: &Q,
) -> Result<Option<IndexedMappedValue<'_>>, Duplicate<IndexedMappedValue<'_>>>
pub fn get_unique_mapped_with_index<Q>( &self, code_map: &CodeMap, offset: usize, key: &Q, ) -> Result<Option<IndexedMappedValue<'_>>, Duplicate<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<&Entry>
pub fn last(&self) -> Option<&Entry>
sourcepub fn push(&mut self, key: Key, value: Value) -> bool
pub fn push(&mut self, key: Key, value: Value) -> 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(&mut self, entry: Entry) -> bool
sourcepub fn push_front(&mut self, key: Key, value: Value) -> bool
pub fn push_front(&mut self, key: Key, value: Value) -> 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, entry: Entry) -> bool
sourcepub fn remove_at(&mut self, index: usize) -> Option<Entry>
pub fn remove_at(&mut self, index: usize) -> Option<Entry>
Removes the entry at the given index.
sourcepub fn insert(
&mut self,
key: Key,
value: Value,
) -> Option<RemovedByInsertion<'_>>
pub fn insert( &mut self, key: Key, value: Value, ) -> Option<RemovedByInsertion<'_>>
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.
sourcepub fn insert_front(
&mut self,
key: Key,
value: Value,
) -> RemovedByInsertFront<'_> ⓘ
pub fn insert_front( &mut self, key: Key, value: Value, ) -> RemovedByInsertFront<'_> ⓘ
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.
sourcepub fn remove<'q, Q>(&mut self, key: &'q Q) -> RemovedEntries<'_, 'q, Q> ⓘ
pub fn remove<'q, Q>(&mut self, key: &'q Q) -> RemovedEntries<'_, 'q, Q> ⓘ
Remove all entries associated to the given key.
Runs in O(n)
time (average).
sourcepub fn remove_unique<Q>(
&mut self,
key: &Q,
) -> Result<Option<Entry>, Duplicate<Entry>>
pub fn remove_unique<Q>( &mut self, key: &Q, ) -> Result<Option<Entry>, Duplicate<Entry>>
Remove the unique entry associated to the given key.
Returns an error if multiple entries match the key.
Runs in O(n)
time (average).
sourcepub fn sort(&mut self)
pub fn sort(&mut self)
Sort the entries by key name.
Entries with the same key are sorted by value.
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. Entries with the same key are sorted by value.
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<'de> Deserialize<'de> for Object
impl<'de> Deserialize<'de> for Object
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>,
source§impl Extend<(SmallString<[u8; 16]>, Value)> for Object
impl Extend<(SmallString<[u8; 16]>, Value)> for Object
source§fn extend<I: IntoIterator<Item = (Key, Value)>>(&mut self, iter: I)
fn extend<I: IntoIterator<Item = (Key, Value)>>(&mut self, iter: I)
source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)source§impl Extend<Entry> for Object
impl Extend<Entry> for Object
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: A)
fn extend_one(&mut self, item: A)
extend_one
)source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)source§impl FromIterator<(SmallString<[u8; 16]>, Value)> for Object
impl FromIterator<(SmallString<[u8; 16]>, Value)> for Object
source§impl FromIterator<Entry> for Object
impl FromIterator<Entry> for Object
source§impl<'de> IntoDeserializer<'de, DeserializeError> for Object
impl<'de> IntoDeserializer<'de, DeserializeError> for Object
§type Deserializer = Value
type Deserializer = Value
source§fn into_deserializer(self) -> Self::Deserializer
fn into_deserializer(self) -> Self::Deserializer
source§impl<'a> IntoIterator for &'a Object
impl<'a> IntoIterator for &'a Object
source§impl<'a> IntoIterator for &'a mut Object
impl<'a> IntoIterator for &'a mut Object
source§impl IntoIterator for Object
impl IntoIterator for Object
source§impl Ord for Object
impl Ord for Object
source§impl PartialEq for Object
impl PartialEq for Object
source§impl PartialOrd for Object
impl PartialOrd for Object
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moresource§impl PrintWithSize for Object
impl PrintWithSize for Object
source§impl UnorderedPartialEq for Object
impl UnorderedPartialEq for Object
fn unordered_eq(&self, other: &Self) -> bool
impl Eq for Object
impl UnorderedEq for Object
Auto Trait Implementations§
impl Freeze for Object
impl RefUnwindSafe for Object
impl Send for Object
impl Sync for Object
impl Unpin for Object
impl UnwindSafe for Object
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> BorrowUnordered for T
impl<T> BorrowUnordered for T
fn as_unordered(&self) -> &Unordered<T>
source§impl<T> CallHasher for T
impl<T> CallHasher for T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)