VObject

Struct VObject 

Source
pub struct VObject(/* private fields */);
Expand description

An object (map) value.

VObject is an ordered map of string keys to Values. It preserves insertion order.

Storage modes:

  • Small mode (default): inline array of KeyValuePair with linear search
  • Large mode (std feature, >= 32 entries): IndexMap for O(1) lookups

Implementations§

Source§

impl VObject

Source

pub fn new() -> Self

Creates a new empty object.

Source

pub fn with_capacity(cap: usize) -> Self

Creates a new object with the specified capacity.

Source

pub fn len(&self) -> usize

Returns the number of entries.

Source

pub fn is_empty(&self) -> bool

Returns true if the object is empty.

Source

pub fn capacity(&self) -> usize

Returns the capacity.

Source

pub fn reserve(&mut self, additional: usize)

Reserves capacity for at least additional more entries.

Source

pub fn get(&self, key: &str) -> Option<&Value>

Gets a value by key.

Source

pub fn get_mut(&mut self, key: &str) -> Option<&mut Value>

Gets a mutable value by key.

Source

pub fn get_key_value(&self, key: &str) -> Option<(&VString, &Value)>

Gets a key-value pair by key.

Source

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

Returns true if the object contains the key.

Source

pub fn insert( &mut self, key: impl Into<VString>, value: impl Into<Value>, ) -> Option<Value>

Inserts a key-value pair. Returns the old value if the key existed.

Source

pub fn remove(&mut self, key: &str) -> Option<Value>

Removes a key-value pair. Returns the value if the key existed.

Source

pub fn remove_entry(&mut self, key: &str) -> Option<(VString, Value)>

Removes and returns a key-value pair.

Source

pub fn clear(&mut self)

Clears the object.

Source

pub fn keys(&self) -> Keys<'_>

Returns an iterator over keys.

Source

pub fn values(&self) -> Values<'_>

Returns an iterator over values.

Source

pub fn values_mut(&mut self) -> ValuesMut<'_>

Returns an iterator over mutable values.

Source

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

Returns an iterator over key-value pairs.

Source

pub fn iter_mut(&mut self) -> IterMut<'_>

Returns an iterator over mutable key-value pairs.

Source

pub fn shrink_to_fit(&mut self)

Shrinks the capacity to match the length.

Source§

impl VObject

Source

pub fn into_value(self) -> Value

Converts this VObject into a Value, consuming self.

Trait Implementations§

Source§

impl AsMut<Value> for VObject

Source§

fn as_mut(&mut self) -> &mut Value

Converts this type into a mutable reference of the (usually inferred) input type.
Source§

impl AsRef<Value> for VObject

Source§

fn as_ref(&self) -> &Value

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl Clone for VObject

Source§

fn clone(&self) -> VObject

Returns a duplicate of the value. Read more
1.0.0§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for VObject

Source§

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

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

impl Default for VObject

Source§

fn default() -> Self

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

impl<K: Into<VString>, V: Into<Value>> Extend<(K, V)> for VObject

Available on crate feature alloc only.
Source§

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

Extends a collection with the contents of an iterator. Read more
§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
§

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<K: Into<VString>, V: Into<Value>> From<BTreeMap<K, V>> for VObject

Available on crate feature alloc only.
Source§

fn from(map: BTreeMap<K, V>) -> Self

Converts to this type from the input type.
Source§

impl<K: Into<VString>, V: Into<Value>> From<HashMap<K, V>> for VObject

Available on crate feature std only.
Source§

fn from(map: HashMap<K, V>) -> Self

Converts to this type from the input type.
Source§

impl From<VObject> for Value

Source§

fn from(obj: VObject) -> Self

Converts to this type from the input type.
Source§

impl<K: Into<VString>, V: Into<Value>> FromIterator<(K, V)> for VObject

Available on crate feature alloc only.
Source§

fn from_iter<I: IntoIterator<Item = (K, V)>>(iter: I) -> Self

Creates a value from an iterator. Read more
Source§

impl Hash for VObject

Source§

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

Feeds this value into the given Hasher. Read more
1.3.0§

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 Index<&str> for VObject

Source§

type Output = Value

The returned type after indexing.
Source§

fn index(&self, key: &str) -> &Value

Performs the indexing (container[index]) operation. Read more
Source§

impl IndexMut<&str> for VObject

Source§

fn index_mut(&mut self, key: &str) -> &mut Value

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl<'a> IntoIterator for &'a VObject

Source§

type Item = (&'a VString, &'a Value)

The type of the elements being iterated over.
Source§

type IntoIter = Iter<'a>

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

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

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

Source§

type Item = (&'a VString, &'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) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl IntoIterator for VObject

Source§

type Item = (VString, Value)

The type of the elements being iterated over.
Source§

type IntoIter = ObjectIntoIter

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

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl PartialEq for VObject

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for VObject

Auto Trait Implementations§

Blanket Implementations§

§

impl<T> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

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

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

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

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> CloneToUninit for T
where T: Clone,

§

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

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Into<U> for T
where U: From<T>,

§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V