[][src]Struct glib::VariantDict

pub struct VariantDict(_);

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

impl VariantDict[src]

pub fn new(from_asv: Option<&Variant>) -> Self[src]

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.

pub fn contains(&self, key: &str) -> bool[src]

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.

pub fn lookup_value(
    &self,
    key: &str,
    expected_type: Option<&VariantTy>
) -> Option<Variant>
[src]

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.

pub fn insert_value(&self, key: &str, value: &Variant)[src]

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.

pub fn insert<T: ToVariant>(&self, key: &str, value: &T)[src]

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.

pub fn remove(&self, key: &str) -> bool[src]

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.

pub unsafe fn end_unsafe(&self) -> Variant[src]

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

pub fn end(&self) -> Variant[src]

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

impl Clone for VariantDict[src]

impl Default for VariantDict[src]

impl From<Variant> for VariantDict[src]

impl FromVariant for VariantDict[src]

impl StaticType for VariantDict[src]

impl StaticVariantType for VariantDict[src]

impl ToVariant for VariantDict[src]

Auto Trait Implementations

impl RefUnwindSafe for VariantDict

impl !Send for VariantDict

impl !Sync for VariantDict

impl Unpin for VariantDict

impl UnwindSafe for VariantDict

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<'a, T> ToGlibContainerFromSlice<'a, *const GList> for T where
    T: GlibPtrDefault + ToGlibPtr<'a, <T as GlibPtrDefault>::GlibType>, 
[src]

impl<'a, T> ToGlibContainerFromSlice<'a, *const GPtrArray> for T where
    T: GlibPtrDefault + ToGlibPtr<'a, <T as GlibPtrDefault>::GlibType>, 
[src]

impl<'a, T> ToGlibContainerFromSlice<'a, *mut GArray> for T where
    T: GlibPtrDefault + ToGlibPtr<'a, <T as GlibPtrDefault>::GlibType>, 
[src]

impl<'a, T> ToGlibContainerFromSlice<'a, *mut GList> for T where
    T: GlibPtrDefault + ToGlibPtr<'a, <T as GlibPtrDefault>::GlibType>, 
[src]

impl<'a, T> ToGlibContainerFromSlice<'a, *mut GPtrArray> for T where
    T: GlibPtrDefault + ToGlibPtr<'a, <T as GlibPtrDefault>::GlibType>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToSendValue for T where
    T: ToValue + SetValue + Send + ?Sized
[src]

impl<T> ToValue for T where
    T: SetValue + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.