#[repr(transparent)]
pub struct VariantDict { /* private fields */ }
Expand description

VariantDict is a mutable key/value store where the keys are always strings and the values are Variants.

Variant dictionaries can easily be converted to/from Variants of the appropriate type. In glib terms, this is a variant of the form "a{sv}".

Panics

Note, pretty much all methods on this struct will panic if the end_unsafe() method was called on the instance.

Implementations

Create a new VariantDict optionally populating it with the given Variant

Since Variants are immutable, this does not couple the VariantDict with the input Variant, instead the contents are copied into the VariantDict.

Panics

This function will panic if the given Variant is not of the correct type.

Check if this VariantDict contains the given key.

Look up whether or not the given key is present, returning true if it is present in self.

Look up a typed value from this VariantDict.

The given key is looked up in self.

This will return None if the key is not present in the dictionary, and an error if the key is present but with the wrong type.

Look up and return a value from this VariantDict.

The given key is looked up in self. If expected_type is not None then it will be matched against the type of any found value.

This will return None if the key is not present in the dictionary or if it is present but the type of the value does not match a given expected_type. Otherwise, Some(value) will be returned where the value is an instance of Variant.

Insert a variant into the dictionary.

The given key/value pair is inserted into self. If a value was previously associated with key then it is overwritten.

For convenience, you may use the insert() if you have a value which implements ToVariant.

Insert a value into the dictionary

The given key/value pair is inserted into self. If a value was previously associated with key then it is overwritten.

This is a convenience method which automatically calls to_variant() for you on the given value.

If, on the other hand, you have a Variant instance already, you should use the insert_value() method instead.

Remove the given key from the dictionary.

This removes the given key from the dictionary, releasing the reference on the associated value if one is present.

If a key/value pair was removed from the dictionary, true is returned. If key was not present then false is returned instead.

Convert this dictionary to a Variant

This method converts self into an instance of Variant but in doing so renders it very unsafe to use.

Safety

After calling this, the underlying GVariantDict is in a state where the only valid operations to perform as reference ones. As such any attempt to read/update the dictionary will fail and emit warnings of such.

You should only use this function if the extra cost of the safe function is too much for your performance critical codepaths

Convert this dictionary to a Variant

This method converts self into an instance of Variant and then reinitialises itself in order to be safe for further use.

If you are certain that nothing other than disposing of references will be done after ending the instance, you can call the end_unsafe() method instead to avoid the unnecessary reinitialisation of the dictionary.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

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

Converts to this type from the input type.

Tries to extract a value. Read more

Returns the type identifier of Self.

Returns the VariantType corresponding to Self.

Returns a Variant clone of self.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

Ensures that the type has been registered with the type system.

The resulting type after obtaining ownership.

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

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

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.