glib

Struct VariantDict

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

GLib type: Shared boxed type with reference counted clone semantics.

Implementations§

Source§

impl VariantDict

Source

pub fn as_ptr(&self) -> *mut GVariantDict

Return the inner pointer to the underlying C value.

Source

pub unsafe fn from_glib_ptr_borrow(ptr: &*mut GVariantDict) -> &Self

Borrows the underlying C value.

Source§

impl VariantDict

Source

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

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.

Source

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

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.

Source

pub fn lookup<T: FromVariant>( &self, key: &str, ) -> Result<Option<T>, VariantTypeMismatchError>

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.

Source

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

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.

Source

pub fn insert_value(&self, key: &str, value: &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.

Source

pub fn insert(&self, key: &str, value: impl Into<Variant>)

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.

Source

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

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.

Source

pub unsafe fn end_unsafe(&self) -> Variant

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

Source

pub fn end(&self) -> Variant

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§

Source§

impl Clone for VariantDict

Source§

fn clone(&self) -> Self

Makes a clone of this shared reference.

This increments the strong reference count of the reference. Dropping the reference will decrement it again.

1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Default for VariantDict

Source§

fn default() -> Self

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

impl From<Variant> for VariantDict

Source§

fn from(other: Variant) -> Self

Converts to this type from the input type.
Source§

impl From<VariantDict> for Value

Source§

fn from(s: VariantDict) -> Self

Converts to this type from the input type.
Source§

impl From<VariantDict> for Variant

Source§

fn from(d: VariantDict) -> Self

Consume a given VariantDict and call VariantDict::end on it.

Note: While this method consumes the VariantDict, the underlying object could still be accessed through other clones because of the reference counted clone semantics.

Source§

impl FromVariant for VariantDict

Source§

fn from_variant(variant: &Variant) -> Option<Self>

Tries to extract a value. Read more
Source§

impl HasParamSpec for VariantDict

Source§

type ParamSpec = ParamSpecBoxed

Source§

type SetValue = VariantDict

Preferred value to be used as setter for the associated ParamSpec.
Source§

type BuilderFn = fn(_: &str) -> ParamSpecBoxedBuilder<'_, VariantDict>

Source§

fn param_spec_builder() -> Self::BuilderFn

Source§

impl StaticType for VariantDict

Source§

fn static_type() -> Type

Returns the type identifier of Self.
Source§

impl StaticVariantType for VariantDict

Source§

fn static_variant_type() -> Cow<'static, VariantTy>

Returns the VariantType corresponding to Self.
Source§

impl ToVariant for VariantDict

Source§

fn to_variant(&self) -> Variant

Returns a Variant clone of self.

Auto Trait Implementations§

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, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GList> for T

Source§

impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GPtrArray> for T

Source§

impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GSList> for T

Source§

impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GList> for T

Source§

impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GPtrArray> for T

Source§

impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GSList> for T

Source§

impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GList> for T

Source§

impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GPtrArray> for T

Source§

impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GSList> for T

Source§

impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GList> for T

Source§

impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GPtrArray> for T

Source§

impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GSList> for T

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> IntoClosureReturnValue for T
where T: Into<Value>,

Source§

impl<T> Property for T
where T: HasParamSpec,

Source§

type Value = T

Source§

impl<T> PropertyGet for T
where T: HasParamSpec,

Source§

type Value = T

Source§

fn get<R, F>(&self, f: F) -> R
where F: Fn(&<T as PropertyGet>::Value) -> R,

Source§

impl<T> StaticTypeExt for T
where T: StaticType,

Source§

fn ensure_type()

Ensures that the type has been registered with the type system.
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> TransparentType for T

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T> TryFromClosureReturnValue for T
where T: for<'a> FromValue<'a> + StaticType + 'static,

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

impl<'a, T, C, E> FromValueOptional<'a> for T
where T: FromValue<'a, Checker = C>, C: ValueTypeChecker<Error = ValueTypeMismatchOrNoneError<E>>, E: Error + Send + 'static,