pub struct Object<'a> { /* private fields */ }Expand description
A UCL object: keys in insertion order, each with one or more values.
Equality ignores key order, like IndexMap; the order of values inside an entry matters.
Comparing and dropping do not recurse (Value).
Implementations§
Source§impl<'a> Object<'a>
impl<'a> Object<'a>
pub fn new() -> Self
pub fn with_capacity(capacity: usize) -> Self
pub fn is_empty(&self) -> bool
pub fn contains_key(&self, key: &str) -> bool
Sourcepub fn get(&self, key: &str) -> Option<&Value<'a>>
pub fn get(&self, key: &str) -> Option<&Value<'a>>
The first value of key, as libucl’s ucl_object_lookup returns it.
Sourcepub fn get_mut(&mut self, key: &str) -> Option<&mut Value<'a>>
pub fn get_mut(&mut self, key: &str) -> Option<&mut Value<'a>>
The first value of key, mutably.
Sourcepub fn get_all(&self, key: &str) -> Values<'_, 'a> ⓘ
pub fn get_all(&self, key: &str) -> Values<'_, 'a> ⓘ
Every value of key in insertion order; empty if the key is absent.
pub fn entry(&self, key: &str) -> Option<&Entry<'a>>
pub fn entry_mut(&mut self, key: &str) -> Option<&mut Entry<'a>>
Sourcepub fn get_index(&self, index: usize) -> Option<(&Str<'a>, &Entry<'a>)>
pub fn get_index(&self, index: usize) -> Option<(&Str<'a>, &Entry<'a>)>
The key and entry at position index in insertion order.
Sourcepub fn get_index_mut(
&mut self,
index: usize,
) -> Option<(&Str<'a>, &mut Entry<'a>)>
pub fn get_index_mut( &mut self, index: usize, ) -> Option<(&Str<'a>, &mut Entry<'a>)>
The key and entry at position index in insertion order, the entry mutable.
Sourcepub fn rename_key(&mut self, old: &str, new: impl Into<Str<'a>>) -> bool
pub fn rename_key(&mut self, old: &str, new: impl Into<Str<'a>>) -> bool
Changes the spelling of key old to new, keeping its position and entry. Returns false
if old is absent or new is another key already present.
Sourcepub fn insert(
&mut self,
key: impl Into<Str<'a>>,
value: Value<'a>,
) -> Option<Entry<'a>>
pub fn insert( &mut self, key: impl Into<Str<'a>>, value: Value<'a>, ) -> Option<Entry<'a>>
Sets key to a single value, replacing every existing value. An existing key keeps its
position.
Sourcepub fn insert_entry(
&mut self,
key: impl Into<Str<'a>>,
entry: Entry<'a>,
) -> Option<Entry<'a>>
pub fn insert_entry( &mut self, key: impl Into<Str<'a>>, entry: Entry<'a>, ) -> Option<Entry<'a>>
Sets key to entry, replacing an existing entry in place.
Sourcepub fn append(&mut self, key: impl Into<Str<'a>>, value: Value<'a>)
pub fn append(&mut self, key: impl Into<Str<'a>>, value: Value<'a>)
Adds a value to key: a new key, or one more value of an existing key (implicit array).
Sourcepub fn remove(&mut self, key: &str) -> Option<Entry<'a>>
pub fn remove(&mut self, key: &str) -> Option<Entry<'a>>
Removes key, keeping the order of the others.
Sourcepub fn remove_index(&mut self, index: usize) -> Option<(Str<'a>, Entry<'a>)>
pub fn remove_index(&mut self, index: usize) -> Option<(Str<'a>, Entry<'a>)>
Removes and returns the entry at index, keeping the order of the others.
Sourcepub fn iter_mut(&mut self) -> IterMut<'_, 'a> ⓘ
pub fn iter_mut(&mut self) -> IterMut<'_, 'a> ⓘ
Keys and entries in insertion order, entries mutable.
pub fn keys(&self) -> Keys<'_, 'a> ⓘ
Sourcepub fn into_owned(self) -> Object<'static>
pub fn into_owned(self) -> Object<'static>
The object with every key and string it borrows copied (Value::into_owned).
Sourcepub fn insert_with_strategy(
&mut self,
key: impl Into<Str<'a>>,
value: Value<'a>,
priority: u8,
strategy: DuplicateStrategy,
flags: ParserFlags,
) -> Result<(), DuplicateKeyError>
pub fn insert_with_strategy( &mut self, key: impl Into<Str<'a>>, value: Value<'a>, priority: u8, strategy: DuplicateStrategy, flags: ParserFlags, ) -> Result<(), DuplicateKeyError>
Inserts value under key, resolving an existing key by strategy and priority,
and applying flags. Behaviour is specified in docs/spec/08-duplicates.md; see
Object::insert_slot_with_strategy.
Sourcepub fn insert_slot_with_strategy(
&mut self,
key: impl Into<Str<'a>>,
slot: Slot<'a>,
strategy: DuplicateStrategy,
flags: ParserFlags,
) -> Result<(), DuplicateKeyError>
pub fn insert_slot_with_strategy( &mut self, key: impl Into<Str<'a>>, slot: Slot<'a>, strategy: DuplicateStrategy, flags: ParserFlags, ) -> Result<(), DuplicateKeyError>
Object::insert_with_strategy for a prepared slot.
Under ParserFlags::KEY_LOWERCASE the key is lowercased first, ASCII letters only
(spec §8.6, §12.1). A new key is added at the end. A key already present keeps its
position, and strategy decides the outcome (spec §8.2–§8.5):
DuplicateStrategy::Append: an inherited first value is replaced. Otherwise the new priority is compared with the first value’s: higher replaces the entry, lower is dropped, equal adds the value (or collects it underParserFlags::NO_IMPLICIT_ARRAYS).DuplicateStrategy::Rewrite: the entry is replaced by the new value.DuplicateStrategy::Error:DuplicateKeyError, with the object unchanged.DuplicateStrategy::Merge: containers are merged, and a scalar first value is resolved as underAppend(see the rules onEntry::mergein the source).
Under Merge, an object is merged into entry by entry, so when a nested insert fails the
entries before it have already been merged.
Sourcepub fn insert_slot_placed(
&mut self,
key: impl Into<Str<'a>>,
slot: Slot<'a>,
strategy: DuplicateStrategy,
flags: ParserFlags,
) -> Result<Placement, DuplicateKeyError>
pub fn insert_slot_placed( &mut self, key: impl Into<Str<'a>>, slot: Slot<'a>, strategy: DuplicateStrategy, flags: ParserFlags, ) -> Result<Placement, DuplicateKeyError>
Object::insert_slot_with_strategy, reporting where the value went.
The key the value is stored under is key, lowercased under
ParserFlags::KEY_LOWERCASE.
Trait Implementations§
Source§impl<'a, K: Into<Str<'a>>> Extend<(K, Value<'a>)> for Object<'a>
impl<'a, K: Into<Str<'a>>> Extend<(K, Value<'a>)> for Object<'a>
Source§fn extend<I: IntoIterator<Item = (K, Value<'a>)>>(&mut self, iter: I)
fn extend<I: IntoIterator<Item = (K, Value<'a>)>>(&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<'a, K: Into<Str<'a>>> FromIterator<(K, Value<'a>)> for Object<'a>
impl<'a, K: Into<Str<'a>>> FromIterator<(K, Value<'a>)> for Object<'a>
Source§fn from_iter<I: IntoIterator<Item = (K, Value<'a>)>>(iter: I) -> Self
fn from_iter<I: IntoIterator<Item = (K, Value<'a>)>>(iter: I) -> Self
Collects pairs with Object::append: a repeated key becomes an implicit array.