Struct json_syntax::object::Object
source · [−]pub struct Object<M> { /* private fields */ }
Expand description
Object.
Implementations
sourceimpl<M> Object<M>
impl<M> Object<M>
pub fn new() -> Self
pub fn from_vec(entries: Vec<Entry<M>>) -> Self
pub fn capacity(&self) -> usize
pub fn len(&self) -> usize
pub fn is_empty(&self) -> bool
pub fn entries(&self) -> &[Entry<M>]
pub fn iter(&self) -> Iter<'_, Entry<M>>
pub fn iter_mut(&mut self) -> IterMut<'_, M>ⓘNotable traits for IterMut<'a, M>impl<'a, M> Iterator for IterMut<'a, M> type Item = (&'a Meta<Key, M>, &'a mut MetaValue<M>);
sourcepub fn get<Q: ?Sized>(&self, key: &Q) -> Values<'_, M>ⓘNotable traits for Values<'a, M>impl<'a, M> Iterator for Values<'a, M> type Item = &'a MetaValue<M>;
where
Q: Hash + Equivalent<Key>,
pub fn get<Q: ?Sized>(&self, key: &Q) -> Values<'_, M>ⓘNotable traits for Values<'a, M>impl<'a, M> Iterator for Values<'a, M> type Item = &'a MetaValue<M>;
where
Q: Hash + Equivalent<Key>,
Returns an iterator over the values matching the given key.
Runs in O(1)
(average).
sourcepub fn get_mut<Q: ?Sized>(&mut self, key: &Q) -> ValuesMut<'_, M>ⓘNotable traits for ValuesMut<'a, M>impl<'a, M> Iterator for ValuesMut<'a, M> type Item = &'a mut MetaValue<M>;
where
Q: Hash + Equivalent<Key>,
pub fn get_mut<Q: ?Sized>(&mut self, key: &Q) -> ValuesMut<'_, M>ⓘNotable traits for ValuesMut<'a, M>impl<'a, M> Iterator for ValuesMut<'a, M> type Item = &'a mut MetaValue<M>;
where
Q: Hash + Equivalent<Key>,
Returns an iterator over the values matching the given key.
Runs in O(1)
(average).
sourcepub fn get_unique<Q: ?Sized>(
&self,
key: &Q
) -> Result<Option<&MetaValue<M>>, Duplicate<&Entry<M>>>where
Q: Hash + Equivalent<Key>,
pub fn get_unique<Q: ?Sized>(
&self,
key: &Q
) -> Result<Option<&MetaValue<M>>, Duplicate<&Entry<M>>>where
Q: Hash + Equivalent<Key>,
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: ?Sized>(
&mut self,
key: &Q
) -> Result<Option<&mut MetaValue<M>>, Duplicate<&Entry<M>>>where
Q: Hash + Equivalent<Key>,
pub fn get_unique_mut<Q: ?Sized>(
&mut self,
key: &Q
) -> Result<Option<&mut MetaValue<M>>, Duplicate<&Entry<M>>>where
Q: Hash + Equivalent<Key>,
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: ?Sized>(&self, key: &Q) -> Entries<'_, M>ⓘNotable traits for Entries<'a, M>impl<'a, M> Iterator for Entries<'a, M> type Item = &'a Entry<M>;
where
Q: Hash + Equivalent<Key>,
pub fn get_entries<Q: ?Sized>(&self, key: &Q) -> Entries<'_, M>ⓘNotable traits for Entries<'a, M>impl<'a, M> Iterator for Entries<'a, M> type Item = &'a Entry<M>;
where
Q: Hash + Equivalent<Key>,
Returns an iterator over the entries matching the given key.
Runs in O(1)
(average).
sourcepub fn get_unique_entry<Q: ?Sized>(
&self,
key: &Q
) -> Result<Option<&Entry<M>>, Duplicate<&Entry<M>>>where
Q: Hash + Equivalent<Key>,
pub fn get_unique_entry<Q: ?Sized>(
&self,
key: &Q
) -> Result<Option<&Entry<M>>, Duplicate<&Entry<M>>>where
Q: Hash + Equivalent<Key>,
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: ?Sized>(&self, key: &Q) -> ValuesWithIndex<'_, M>ⓘNotable traits for ValuesWithIndex<'a, M>impl<'a, M> Iterator for ValuesWithIndex<'a, M> type Item = (usize, &'a MetaValue<M>);
where
Q: Hash + Equivalent<Key>,
pub fn get_with_index<Q: ?Sized>(&self, key: &Q) -> ValuesWithIndex<'_, M>ⓘNotable traits for ValuesWithIndex<'a, M>impl<'a, M> Iterator for ValuesWithIndex<'a, M> type Item = (usize, &'a MetaValue<M>);
where
Q: Hash + Equivalent<Key>,
Returns an iterator over the entries matching the given key.
Runs in O(1)
(average).
sourcepub fn get_entries_with_index<Q: ?Sized>(
&self,
key: &Q
) -> EntriesWithIndex<'_, M>ⓘNotable traits for EntriesWithIndex<'a, M>impl<'a, M> Iterator for EntriesWithIndex<'a, M> type Item = (usize, &'a Entry<M>);
where
Q: Hash + Equivalent<Key>,
pub fn get_entries_with_index<Q: ?Sized>(
&self,
key: &Q
) -> EntriesWithIndex<'_, M>ⓘNotable traits for EntriesWithIndex<'a, M>impl<'a, M> Iterator for EntriesWithIndex<'a, M> type Item = (usize, &'a Entry<M>);
where
Q: Hash + Equivalent<Key>,
Returns an iterator over the entries matching the given key.
Runs in O(1)
(average).
pub fn index_of<Q: ?Sized>(&self, key: &Q) -> Option<usize>where
Q: Hash + Equivalent<Key>,
pub fn redundant_index_of<Q: ?Sized>(&self, key: &Q) -> Option<usize>where
Q: Hash + Equivalent<Key>,
pub fn indexes_of<Q: ?Sized>(&self, key: &Q) -> Indexes<'_>ⓘNotable traits for Indexes<'a>impl<'a> Iterator for Indexes<'a> type Item = usize;
where
Q: Hash + Equivalent<Key>,
pub fn first(&self) -> Option<&Entry<M>>
pub fn last(&self) -> Option<&Entry<M>>
sourcepub fn push(&mut self, key: Meta<Key, M>, value: MetaValue<M>) -> bool
pub fn push(&mut self, key: Meta<Key, M>, value: MetaValue<M>) -> 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<M>) -> bool
sourcepub fn remove_at(&mut self, index: usize) -> Option<Entry<M>>
pub fn remove_at(&mut self, index: usize) -> Option<Entry<M>>
Removes the entry at the given index.
sourcepub fn insert(
&mut self,
key: Meta<Key, M>,
value: MetaValue<M>
) -> Option<RemovedByInsertion<'_, M>>
pub fn insert(
&mut self,
key: Meta<Key, M>,
value: MetaValue<M>
) -> Option<RemovedByInsertion<'_, M>>
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 remove<'q, Q: ?Sized>(
&mut self,
key: &'q Q
) -> RemovedEntries<'_, 'q, M, Q>ⓘNotable traits for RemovedEntries<'a, 'q, M, Q>impl<'a, 'q, M, Q: ?Sized> Iterator for RemovedEntries<'a, 'q, M, Q>where
Q: Hash + Equivalent<Key>, type Item = Entry<M>;
where
Q: Hash + Equivalent<Key>,
pub fn remove<'q, Q: ?Sized>(
&mut self,
key: &'q Q
) -> RemovedEntries<'_, 'q, M, Q>ⓘNotable traits for RemovedEntries<'a, 'q, M, Q>impl<'a, 'q, M, Q: ?Sized> Iterator for RemovedEntries<'a, 'q, M, Q>where
Q: Hash + Equivalent<Key>, type Item = Entry<M>;
where
Q: Hash + Equivalent<Key>,
Q: Hash + Equivalent<Key>, type Item = Entry<M>;
Remove all entries associated to the given key.
Runs in O(n)
time (average).
sourcepub fn remove_unique<Q: ?Sized>(
&mut self,
key: &Q
) -> Result<Option<Entry<M>>, Duplicate<Entry<M>>>where
Q: Hash + Equivalent<Key>,
pub fn remove_unique<Q: ?Sized>(
&mut self,
key: &Q
) -> Result<Option<Entry<M>>, Duplicate<Entry<M>>>where
Q: Hash + Equivalent<Key>,
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 map_metadata<N>(self, f: impl FnMut(M) -> N) -> Object<N>
pub fn map_metadata<N>(self, f: impl FnMut(M) -> N) -> Object<N>
Recursively maps the metadata inside the object.
Trait Implementations
sourceimpl<M> Extend<(Meta<SmallString<[u8; 16]>, M>, Meta<Value<M>, M>)> for Object<M>
impl<M> Extend<(Meta<SmallString<[u8; 16]>, M>, Meta<Value<M>, M>)> for Object<M>
sourcefn extend<I: IntoIterator<Item = (Meta<Key, M>, MetaValue<M>)>>(
&mut self,
iter: I
)
fn extend<I: IntoIterator<Item = (Meta<Key, M>, MetaValue<M>)>>(
&mut self,
iter: I
)
sourcefn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)sourcefn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)sourceimpl<M> Extend<Entry<M>> for Object<M>
impl<M> Extend<Entry<M>> for Object<M>
sourcefn extend<I: IntoIterator<Item = Entry<M>>>(&mut self, iter: I)
fn extend<I: IntoIterator<Item = Entry<M>>>(&mut self, iter: I)
sourcefn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)sourcefn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)sourceimpl<M> FromIterator<(Meta<SmallString<[u8; 16]>, M>, Meta<Value<M>, M>)> for Object<M>
impl<M> FromIterator<(Meta<SmallString<[u8; 16]>, M>, Meta<Value<M>, M>)> for Object<M>
sourceimpl<M> FromIterator<Entry<M>> for Object<M>
impl<M> FromIterator<Entry<M>> for Object<M>
sourcefn from_iter<I: IntoIterator<Item = Entry<M>>>(iter: I) -> Self
fn from_iter<I: IntoIterator<Item = Entry<M>>>(iter: I) -> Self
sourceimpl<'a, M> IntoIterator for &'a Object<M>
impl<'a, M> IntoIterator for &'a Object<M>
sourceimpl<M> IntoIterator for Object<M>
impl<M> IntoIterator for Object<M>
sourceimpl<M: Ord> Ord for Object<M>
impl<M: Ord> Ord for Object<M>
1.21.0 · sourcefn max(self, other: Self) -> Self
fn max(self, other: Self) -> Self
1.21.0 · sourcefn min(self, other: Self) -> Self
fn min(self, other: Self) -> Self
1.50.0 · sourcefn clamp(self, min: Self, max: Self) -> Selfwhere
Self: PartialOrd<Self>,
fn clamp(self, min: Self, max: Self) -> Selfwhere
Self: PartialOrd<Self>,
sourceimpl<M: PartialOrd> PartialOrd<Object<M>> for Object<M>
impl<M: PartialOrd> PartialOrd<Object<M>> for Object<M>
sourcefn partial_cmp(&self, other: &Self) -> Option<Ordering>
fn partial_cmp(&self, other: &Self) -> Option<Ordering>
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read more