Skip to main content

Object

Struct Object 

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

Object.

Implementations§

Source§

impl Object

Source

pub fn new() -> Object

Creates a new empty object.

Source

pub fn with_capacity(capacity: usize) -> Object

Creates a new empty object with room for capacity entries.

Source

pub fn from_vec(entries: Vec<Entry>) -> Object

Builds an object from a list of entries, keeping their order and any duplicate keys.

Source

pub const fn capacity(&self) -> usize

Returns the number of entries this object can hold without reallocating.

Source

pub const fn len(&self) -> usize

Returns the number of entries in this object, duplicates included.

Source

pub const fn is_empty(&self) -> bool

Checks if this object has no entries.

Source

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.

Source

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.

Source

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

Returns the entries of this object as a slice, in definition order.

Source

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

Iterates over the entries of this object, in definition order.

Source

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.

Source

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.

Source

pub fn contains_key<Q>(&self, key: &Q) -> bool

Checks if this object contains the given key.

Runs in O(1) (average).

Source

pub fn get<Q>(&self, key: &Q) -> Values<'_> ⓘ

Returns an iterator over the values matching the given key.

Runs in O(1) (average).

Source

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).

Source

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).

§Errors

Returns Duplicate if more than one entry matches key.

Source

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).

§Errors

Returns Duplicate if more than one entry matches key.

Source

pub fn get_entries<Q>(&self, key: &Q) -> Entries<'_> ⓘ

Returns an iterator over the entries matching the given key.

Runs in O(1) (average).

Source

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).

§Errors

Returns Duplicate if more than one entry matches key.

Source

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).

Source

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).

Source

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.

Source

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.

Source

pub fn index_of<Q>(&self, key: &Q) -> Option<usize>

Returns the position of the first entry matching key.

Runs in O(1) (average).

Source

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).

Source

pub fn indexes_of<Q>(&self, key: &Q) -> Indexes<'_> ⓘ

Iterates over the positions of every entry matching key.

Runs in O(1) (average).

Source

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.

Source

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>>>>>

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.

§Errors

Returns Duplicate if more than one entry matches key.

Source

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.

Source

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>>>)>>

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.

§Errors

Returns Duplicate if more than one entry matches key.

Source

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.

Source

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.

§Errors

Returns Duplicate if more than one entry matches key.

Source

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.

Source

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>)>>

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.

§Errors

Returns Duplicate if more than one entry matches key.

Source

pub fn first(&self) -> Option<&Entry>

Returns the first entry of this object.

Source

pub fn last(&self) -> Option<&Entry>

Returns the last entry of this object.

Source

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).

Source

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).

Source

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).

Source

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).

Source

pub fn remove_at(&mut self, index: usize) -> Option<Entry>

Removes the entry at the given index.

Source

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.

Source

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.

Source

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).

Source

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).

§Errors

Returns Duplicate if more than one entry matches key.

Source

pub fn sort(&mut self)

Sort the entries by key name.

Entries with the same key are sorted by value.

Trait Implementations§

Source§

impl Clone for Object

Source§

fn clone(&self) -> Object

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 Object

Source§

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

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

impl Default for Object

Source§

fn default() -> Object

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

impl<'de> Deserialize<'de> for Object

Source§

fn deserialize<D>( deserializer: D, ) -> Result<Object, <D as Deserializer<'de>>::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Drop for Object

Source§

fn drop(&mut self)

Drops the entries without recursing: every nested container is moved onto a heap worklist and emptied there before it drops, so each drop only ever sees empty children. An object holding no nested container allocates nothing.

Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl Eq for Object

Source§

impl Extend<(CompactString, Value)> for Object

Source§

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

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 Extend<Entry> for Object

Source§

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

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<Object> for Value

Source§

fn from(o: Object) -> Value

Converts to this type from the input type.
Source§

impl From<Vec<Entry>> for Object

Source§

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

Converts to this type from the input type.
Source§

impl FromIterator<(CompactString, Value)> for Object

Source§

fn from_iter<I>(iter: I) -> Object
where I: IntoIterator<Item = (CompactString, Value)>,

Creates a value from an iterator. Read more
Source§

impl FromIterator<Entry> for Object

Source§

fn from_iter<I>(iter: I) -> Object
where I: IntoIterator<Item = Entry>,

Creates a value from an iterator. Read more
Source§

impl Hash for Object

Source§

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

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 IntoDeserializer<'_, DeserializeError> for Object

Source§

type Deserializer = Value

The type of the deserializer being converted into.
Source§

fn into_deserializer( self, ) -> <Object as IntoDeserializer<'_, DeserializeError>>::Deserializer

Convert this value into a deserializer.
Source§

impl<'a> IntoIterator for &'a Object

Source§

type Item = &'a Entry

The type of the elements being iterated over.
Source§

type IntoIter = Iter<'a, Entry>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> <&'a Object as IntoIterator>::IntoIter

Creates an iterator from a value. Read more
Source§

impl<'a> IntoIterator for &'a mut Object

Source§

type Item = (&'a CompactString, &'a mut Value)

The type of the elements being iterated over.
Source§

type IntoIter = IterMut<'a>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> <&'a mut Object as IntoIterator>::IntoIter

Creates an iterator from a value. Read more
Source§

impl IntoIterator for Object

Source§

type Item = Entry

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<Entry>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> <Object as IntoIterator>::IntoIter

Creates an iterator from a value. Read more
Source§

impl Ord for Object

Source§

fn cmp(&self, other: &Object) -> 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 Object

Source§

fn eq(&self, other: &Object) -> 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 Object

Source§

fn partial_cmp(&self, other: &Object) -> 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 PrintWithSize for Object

Source§

fn fmt_with_size( &self, f: &mut Formatter<'_>, options: &Options, indent: usize, sizes: &[Size], index: &mut usize, ) -> Result<(), Error>

Writes the value to f, taking its layout from sizes[*index]. Read more
Source§

impl Serialize for Object

Source§

fn serialize<S>( &self, serializer: S, ) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl UnorderedEq for Object

Source§

impl UnorderedPartialEq for Object

Source§

fn unordered_eq(&self, other: &Object) -> bool

Checks if self and other are equal modulo object entry order.

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> BorrowUnordered for T

Source§

fn as_unordered(&self) -> &Unordered<T>

Views this value as an Unordered reference.
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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

Checks if self is equivalent to key.
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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

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

Checks if this value is equivalent to the given key. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, C> FromWithContext<T, C> for T

Source§

fn from_with(value: T, _context: &C) -> T

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, U, C> IntoWithContext<U, C> for T
where U: FromWithContext<T, C>,

Source§

fn into_with(self, context: &C) -> U

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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, C> TryFromWithContext<U, C> for T
where U: IntoWithContext<T, C>,

Source§

type Error = !

Source§

fn try_from_with( value: U, context: &C, ) -> Result<T, <T as TryFromWithContext<U, C>>::Error>

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.
Source§

impl<T, U, C> TryIntoWithContext<U, C> for T
where U: TryFromWithContext<T, C>,

Source§

type Error = <U as TryFromWithContext<T, C>>::Error

Source§

fn try_into_with( self, context: &C, ) -> Result<U, <T as TryIntoWithContext<U, C>>::Error>

Source§

impl<T> WithContext for T
where T: ?Sized,

Source§

fn with<C>(&self, context: C) -> Contextual<&T, C>

Source§

fn into_with<C>(self, context: C) -> Contextual<T, C>
where T: Sized,