Struct glib::VariantDict[][src]

pub struct VariantDict(_);
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 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 subsequent to 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

Performs the conversion.

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

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

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

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

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.