pub struct Object { /* private fields */ }
Expand description
Type representing a HCL object.
Implementations§
Source§impl Object
impl Object
Sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Constructs a new, empty Object
with at least the specified capacity.
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the number of items in the object, also referred to as its ‘length’.
Sourcepub fn contains_key(&self, key: &ObjectKey) -> bool
pub fn contains_key(&self, key: &ObjectKey) -> bool
Return true
if an equivalent to key
exists in the object.
Sourcepub fn get(&self, key: &ObjectKey) -> Option<&ObjectValue>
pub fn get(&self, key: &ObjectKey) -> Option<&ObjectValue>
Return a reference to the value stored for key
, if it is present, else None
.
Sourcepub fn get_mut(&mut self, key: &ObjectKey) -> Option<&mut ObjectValue>
pub fn get_mut(&mut self, key: &ObjectKey) -> Option<&mut ObjectValue>
Return a mutable reference to the value stored for key
, if it is present, else None
.
Sourcepub fn get_key_value(
&self,
key: &ObjectKey,
) -> Option<(&ObjectKey, &ObjectValue)>
pub fn get_key_value( &self, key: &ObjectKey, ) -> Option<(&ObjectKey, &ObjectValue)>
Return references to the key-value pair stored for key
, if it is present, else None
.
Sourcepub fn get_key_value_mut<'a>(
&'a mut self,
key: &ObjectKey,
) -> Option<(ObjectKeyMut<'a>, &'a mut ObjectValue)>
pub fn get_key_value_mut<'a>( &'a mut self, key: &ObjectKey, ) -> Option<(ObjectKeyMut<'a>, &'a mut ObjectValue)>
Return mutable references to the key-value pair stored for key
, if it is present, else None
.
Sourcepub fn insert(
&mut self,
key: impl Into<ObjectKey>,
value: impl Into<ObjectValue>,
) -> Option<ObjectValue>
pub fn insert( &mut self, key: impl Into<ObjectKey>, value: impl Into<ObjectValue>, ) -> Option<ObjectValue>
Insert a key-value pair into the object.
If an equivalent key already exists in the object: the key remains and retains in its place
in the order, its corresponding value is updated with value
and the older value is
returned inside Some(_)
.
If no equivalent key existed in the object: the new key-value pair is inserted, last in
order, and None
is returned.
Sourcepub fn remove(&mut self, key: &ObjectKey) -> Option<ObjectValue>
pub fn remove(&mut self, key: &ObjectKey) -> Option<ObjectValue>
Remove the key-value pair equivalent to key
and return its value.
Like Vec::remove
, the pair is removed by shifting all of the elements that follow it,
preserving their relative order. This perturbs the index of all of those elements!
Sourcepub fn remove_entry(
&mut self,
key: &ObjectKey,
) -> Option<(ObjectKey, ObjectValue)>
pub fn remove_entry( &mut self, key: &ObjectKey, ) -> Option<(ObjectKey, ObjectValue)>
Remove and return the key-value pair equivalent to key
.
Like Vec::remove
, the pair is removed by shifting all of the elements that follow it,
preserving their relative order. This perturbs the index of all of those elements!
Sourcepub fn iter(&self) -> ObjectIter<'_>
pub fn iter(&self) -> ObjectIter<'_>
An iterator visiting all key-value pairs in insertion order. The iterator element type is
(&'a ObjectKey, &'a ObjectValue)
.
Sourcepub fn iter_mut(&mut self) -> ObjectIterMut<'_>
pub fn iter_mut(&mut self) -> ObjectIterMut<'_>
An iterator visiting all key-value pairs in insertion order, with mutable references to the
values. The iterator element type is (ObjectKeyMut<'a>, &'a mut ObjectValue)
.
Sourcepub fn trailing(&self) -> &RawString
pub fn trailing(&self) -> &RawString
Return a reference to raw trailing decor before the object’s closing }
.
Sourcepub fn set_trailing(&mut self, trailing: impl Into<RawString>)
pub fn set_trailing(&mut self, trailing: impl Into<RawString>)
Set the raw trailing decor before the object’s closing }
.
Trait Implementations§
Source§impl<K, V> Extend<(K, V)> for Object
impl<K, V> Extend<(K, V)> for Object
Source§fn extend<I>(&mut self, iterable: I)where
I: IntoIterator<Item = (K, V)>,
fn extend<I>(&mut self, iterable: I)where
I: IntoIterator<Item = (K, V)>,
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
)