Skip to main content

Object

Struct Object 

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

Source

pub fn new() -> Self

Source

pub fn with_capacity(capacity: usize) -> Self

Source

pub fn len(&self) -> usize

Number of keys.

Source

pub fn is_empty(&self) -> bool

Source

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

Source

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

The first value of key, as libucl’s ucl_object_lookup returns it.

Source

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

The first value of key, mutably.

Source

pub fn get_all(&self, key: &str) -> Values<'_, 'a> ⓘ

Every value of key in insertion order; empty if the key is absent.

Source

pub fn entry(&self, key: &str) -> Option<&Entry<'a>>

Source

pub fn entry_mut(&mut self, key: &str) -> Option<&mut Entry<'a>>

Source

pub fn get_index(&self, index: usize) -> Option<(&Str<'a>, &Entry<'a>)>

The key and entry at position index in insertion order.

Source

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.

Source

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

The position of key in insertion order.

Source

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.

Source

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.

Source

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.

Source

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

Source

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

Removes key, keeping the order of the others.

Source

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.

Source

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

Keys and entries in insertion order.

Source

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

Keys and entries in insertion order, entries mutable.

Source

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

Source

pub fn entries(&self) -> Entries<'_, 'a> ⓘ

Entries in insertion order.

Source

pub fn into_owned(self) -> Object<'static>

The object with every key and string it borrows copied (Value::into_owned).

Source

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.

Source

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

Under Merge, an object is merged into entry by entry, so when a nested insert fails the entries before it have already been merged.

Source

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> Clone for Object<'a>

Source§

fn clone(&self) -> Self

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

As the struct UclObject with its entries, the form of the owned objects of 0.3.

Source§

impl<'a> Default for Object<'a>

Source§

fn default() -> Self

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

impl Drop for Object<'_>

Source§

fn drop(&mut self)

Without recursion, as an Array drops.

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

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

Collects pairs with Object::append: a repeated key becomes an implicit array.

Source§

impl<'a> Index<&str> for Object<'a>

Source§

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

The first value of key. Panics if the key is absent.

Source§

type Output = Value<'a>

The returned type after indexing.
Source§

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

Source§

type Item = (Str<'a>, Entry<'a>)

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<'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<'v, 'a> IntoIterator for &'v Object<'a>

Source§

type Item = (&'v Str<'a>, &'v Entry<'a>)

The type of the elements being iterated over.
Source§

type IntoIter = Iter<'v, '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<'b> PartialEq<Object<'b>> for Object<'_>

See Value’s PartialEq.

Source§

fn eq(&self, other: &Object<'b>) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl Serialize for Object<'_>

Source§

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

As Serialize for UclValue serializes the object.

Auto Trait Implementations§

§

impl<'a> Freeze for Object<'a>

§

impl<'a> RefUnwindSafe for Object<'a>

§

impl<'a> Send for Object<'a>

§

impl<'a> Sync for Object<'a>

§

impl<'a> Unpin for Object<'a>

§

impl<'a> UnsafeUnpin for Object<'a>

§

impl<'a> UnwindSafe for Object<'a>

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> 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<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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