pub struct Object { /* private fields */ }Expand description
Object.
Implementations§
Source§impl Object
impl Object
Sourcepub fn with_capacity(capacity: usize) -> Object
pub fn with_capacity(capacity: usize) -> Object
Creates a new empty object with room for capacity entries.
Sourcepub fn from_vec(entries: Vec<Entry>) -> Object
pub fn from_vec(entries: Vec<Entry>) -> Object
Builds an object from a list of entries, keeping their order and any duplicate keys.
Sourcepub const fn capacity(&self) -> usize
pub const fn capacity(&self) -> usize
Returns the number of entries this object can hold without reallocating.
Sourcepub const fn len(&self) -> usize
pub const fn len(&self) -> usize
Returns the number of entries in this object, duplicates included.
Sourcepub fn contains_duplicate_keys(&self) -> bool
pub fn contains_duplicate_keys(&self) -> bool
Whether two entries of this object share a key.
Runs in O(n) over the key index; the object’s descendants are not
inspected.
Sourcepub fn get_fragment(&self, index: usize) -> Result<FragmentRef<'_>, usize>
pub fn get_fragment(&self, index: usize) -> Result<FragmentRef<'_>, usize>
Returns the fragment at the given index, relative to the contents
of this object: index 0 is the first entry.
On failure, returns the number of fragments left to skip.
§Errors
Returns the number of fragments left to skip when index does not resolve
to a fragment within this object.
Sourcepub fn entries(&self) -> &[Entry]
pub fn entries(&self) -> &[Entry]
Returns the entries of this object as a slice, in definition order.
Sourcepub fn iter(&self) -> Iter<'_, Entry> ⓘ
pub fn iter(&self) -> Iter<'_, Entry> ⓘ
Iterates over the entries of this object, in definition order.
Sourcepub fn iter_mut(&mut self) -> IterMut<'_> ⓘ
pub fn iter_mut(&mut self) -> IterMut<'_> ⓘ
Iterates over the entries of this object, yielding mutable values.
Keys are not mutable: changing one would invalidate the key index.
Sourcepub fn iter_mapped<'m>(
&self,
code_map: &'m CodeMap,
offset: usize,
) -> IterMapped<'_, 'm> ⓘ
pub fn iter_mapped<'m>( &self, code_map: &'m CodeMap, offset: usize, ) -> IterMapped<'_, 'm> ⓘ
Iterates over the entries of this object, pairing each entry, key and
value with its offset in code_map.
offset is the code map offset of the object itself.
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_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>>
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_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,
) -> &Valuewhere
Q: Hash + Equivalent<CompactString> + ToOwned + ?Sized,
<Q as ToOwned>::Owned: Into<CompactString>,
pub fn get_or_insert_with<Q>(
&mut self,
key: &Q,
f: impl FnOnce() -> Value,
) -> &Valuewhere
Q: Hash + Equivalent<CompactString> + ToOwned + ?Sized,
<Q as ToOwned>::Owned: Into<CompactString>,
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 Valuewhere
Q: Hash + Equivalent<CompactString> + ToOwned + ?Sized,
<Q as ToOwned>::Owned: Into<CompactString>,
pub fn get_mut_or_insert_with<Q>(
&mut self,
key: &Q,
f: impl FnOnce() -> Value,
) -> &mut Valuewhere
Q: Hash + Equivalent<CompactString> + ToOwned + ?Sized,
<Q as ToOwned>::Owned: Into<CompactString>,
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.
Sourcepub fn index_of<Q>(&self, key: &Q) -> Option<usize>
pub fn index_of<Q>(&self, key: &Q) -> Option<usize>
Returns the position of the first entry matching key.
Runs in O(1) (average).
Sourcepub fn redundant_index_of<Q>(&self, key: &Q) -> Option<usize>
pub fn redundant_index_of<Q>(&self, key: &Q) -> Option<usize>
Returns the position of the second entry matching key, if the key
is duplicated.
Runs in O(1) (average).
Sourcepub fn indexes_of<Q>(&self, key: &Q) -> Indexes<'_> ⓘ
pub fn indexes_of<Q>(&self, key: &Q) -> Indexes<'_> ⓘ
Iterates over the positions of every entry matching key.
Runs in O(1) (average).
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<Mapped<Entry<Mapped<&CompactString>, Mapped<&Value>>>>, Duplicate<Mapped<Entry<Mapped<&CompactString>, Mapped<&Value>>>>>
pub fn get_unique_mapped_entry<Q>( &self, code_map: &CodeMap, offset: usize, key: &Q, ) -> Result<Option<Mapped<Entry<Mapped<&CompactString>, Mapped<&Value>>>>, Duplicate<Mapped<Entry<Mapped<&CompactString>, Mapped<&Value>>>>>
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<(usize, Mapped<Entry<Mapped<&CompactString>, Mapped<&Value>>>)>, Duplicate<(usize, Mapped<Entry<Mapped<&CompactString>, Mapped<&Value>>>)>>
pub fn get_unique_mapped_entry_with_index<Q>( &self, code_map: &CodeMap, offset: usize, key: &Q, ) -> Result<Option<(usize, Mapped<Entry<Mapped<&CompactString>, Mapped<&Value>>>)>, Duplicate<(usize, Mapped<Entry<Mapped<&CompactString>, Mapped<&Value>>>)>>
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>>>
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<(usize, Mapped<&Value>)>, Duplicate<(usize, Mapped<&Value>)>>
pub fn get_unique_mapped_with_index<Q>( &self, code_map: &CodeMap, offset: usize, key: &Q, ) -> Result<Option<(usize, Mapped<&Value>)>, Duplicate<(usize, Mapped<&Value>)>>
Sourcepub fn push(&mut self, key: CompactString, value: Value) -> bool
pub fn push(&mut self, key: CompactString, 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).
Sourcepub fn push_entry(&mut self, entry: Entry) -> bool
pub fn push_entry(&mut self, entry: Entry) -> bool
Push the given entry to the end of the object.
Returns true if its key was not already present in the object.
Runs in O(1).
Sourcepub fn push_front(&mut self, key: CompactString, value: Value) -> bool
pub fn push_front(&mut self, key: CompactString, 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).
Sourcepub fn push_entry_front(&mut self, entry: Entry) -> bool
pub fn push_entry_front(&mut self, entry: Entry) -> bool
Push the given entry to the top of the object.
Returns true if its key was not already present in the object.
Runs in O(n).
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: CompactString,
value: Value,
) -> Option<RemovedByInsertion<'_>>
pub fn insert( &mut self, key: CompactString, 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: CompactString,
value: Value,
) -> RemovedByInsertFront<'_> ⓘ
pub fn insert_front( &mut self, key: CompactString, 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 const fn remove<'q, Q>(&mut self, key: &'q Q) -> RemovedEntries<'_, 'q, Q> ⓘ
pub const 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).
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Object
impl<'de> Deserialize<'de> for Object
Source§fn deserialize<D>(
deserializer: D,
) -> Result<Object, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
fn deserialize<D>(
deserializer: D,
) -> Result<Object, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
Source§impl Drop for Object
impl Drop for Object
impl Eq for Object
Source§impl Extend<(CompactString, Value)> for Object
impl Extend<(CompactString, Value)> for Object
Source§fn extend<I>(&mut self, iter: I)
fn extend<I>(&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 Extend<Entry> for Object
impl Extend<Entry> for Object
Source§fn extend<I>(&mut self, iter: I)where
I: IntoIterator<Item = Entry>,
fn extend<I>(&mut self, iter: I)where
I: IntoIterator<Item = Entry>,
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 FromIterator<(CompactString, Value)> for Object
impl FromIterator<(CompactString, Value)> for Object
Source§impl FromIterator<Entry> for Object
impl FromIterator<Entry> for Object
Source§impl IntoDeserializer<'_, DeserializeError> for Object
impl IntoDeserializer<'_, DeserializeError> for Object
Source§type Deserializer = Value
type Deserializer = Value
Source§fn into_deserializer(
self,
) -> <Object as IntoDeserializer<'_, DeserializeError>>::Deserializer
fn into_deserializer( self, ) -> <Object as IntoDeserializer<'_, DeserializeError>>::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
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 PartialOrd for Object
impl PartialOrd for Object
Source§impl PrintWithSize for Object
impl PrintWithSize for Object
Source§impl Serialize for Object
impl Serialize for Object
Source§fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
impl UnorderedEq for Object
Source§impl UnorderedPartialEq for Object
impl UnorderedPartialEq for Object
Source§fn unordered_eq(&self, other: &Object) -> bool
fn unordered_eq(&self, other: &Object) -> bool
self and other are equal modulo object entry order.Auto Trait Implementations§
impl Freeze for Object
impl RefUnwindSafe for Object
impl Send for Object
impl Sync for Object
impl Unpin for Object
impl UnsafeUnpin 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
Source§fn as_unordered(&self) -> &Unordered<T>
fn as_unordered(&self) -> &Unordered<T>
Unordered reference.impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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
self is equivalent to key.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.