Struct glib::VariantDict

source ·
#[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§

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<'a>( ptr: *const *const GVariantDict ) -> &'a 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

Returns a copy of the value. Read more
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

Converts to this type from the input type.
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

§

type ParamSpec = ParamSpecBoxed

§

type SetValue = VariantDict

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

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 Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. 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 Twhere T: GlibPtrDefault + FromGlibPtrNone<<T as GlibPtrDefault>::GlibType> + FromGlibPtrFull<<T as GlibPtrDefault>::GlibType>,

source§

impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GPtrArray> for Twhere T: GlibPtrDefault + FromGlibPtrNone<<T as GlibPtrDefault>::GlibType> + FromGlibPtrFull<<T as GlibPtrDefault>::GlibType>,

source§

unsafe fn from_glib_none_num_as_vec( ptr: *const GPtrArray, num: usize ) -> Vec<T, Global>

source§

unsafe fn from_glib_container_num_as_vec( _: *const GPtrArray, _: usize ) -> Vec<T, Global>

source§

unsafe fn from_glib_full_num_as_vec( _: *const GPtrArray, _: usize ) -> Vec<T, Global>

source§

impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GSList> for Twhere T: GlibPtrDefault + FromGlibPtrNone<<T as GlibPtrDefault>::GlibType> + FromGlibPtrFull<<T as GlibPtrDefault>::GlibType>,

source§

unsafe fn from_glib_none_num_as_vec( ptr: *const GSList, num: usize ) -> Vec<T, Global>

source§

unsafe fn from_glib_container_num_as_vec( _: *const GSList, _: usize ) -> Vec<T, Global>

source§

unsafe fn from_glib_full_num_as_vec( _: *const GSList, _: usize ) -> Vec<T, Global>

source§

impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GList> for Twhere T: GlibPtrDefault + FromGlibPtrNone<<T as GlibPtrDefault>::GlibType> + FromGlibPtrFull<<T as GlibPtrDefault>::GlibType>,

source§

unsafe fn from_glib_none_num_as_vec( ptr: *mut GList, num: usize ) -> Vec<T, Global>

source§

unsafe fn from_glib_container_num_as_vec( ptr: *mut GList, num: usize ) -> Vec<T, Global>

source§

unsafe fn from_glib_full_num_as_vec( ptr: *mut GList, num: usize ) -> Vec<T, Global>

source§

impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GPtrArray> for Twhere T: GlibPtrDefault + FromGlibPtrNone<<T as GlibPtrDefault>::GlibType> + FromGlibPtrFull<<T as GlibPtrDefault>::GlibType>,

source§

unsafe fn from_glib_none_num_as_vec( ptr: *mut GPtrArray, num: usize ) -> Vec<T, Global>

source§

unsafe fn from_glib_container_num_as_vec( ptr: *mut GPtrArray, num: usize ) -> Vec<T, Global>

source§

unsafe fn from_glib_full_num_as_vec( ptr: *mut GPtrArray, num: usize ) -> Vec<T, Global>

source§

impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GSList> for Twhere T: GlibPtrDefault + FromGlibPtrNone<<T as GlibPtrDefault>::GlibType> + FromGlibPtrFull<<T as GlibPtrDefault>::GlibType>,

source§

unsafe fn from_glib_none_num_as_vec( ptr: *mut GSList, num: usize ) -> Vec<T, Global>

source§

unsafe fn from_glib_container_num_as_vec( ptr: *mut GSList, num: usize ) -> Vec<T, Global>

source§

unsafe fn from_glib_full_num_as_vec( ptr: *mut GSList, num: usize ) -> Vec<T, Global>

source§

impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GList> for Twhere T: GlibPtrDefault + FromGlibPtrNone<<T as GlibPtrDefault>::GlibType> + FromGlibPtrFull<<T as GlibPtrDefault>::GlibType>,

source§

impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GPtrArray> for Twhere T: GlibPtrDefault + FromGlibPtrNone<<T as GlibPtrDefault>::GlibType> + FromGlibPtrFull<<T as GlibPtrDefault>::GlibType>,

source§

unsafe fn from_glib_none_as_vec(ptr: *const GPtrArray) -> Vec<T, Global>

source§

unsafe fn from_glib_container_as_vec(_: *const GPtrArray) -> Vec<T, Global>

source§

unsafe fn from_glib_full_as_vec(_: *const GPtrArray) -> Vec<T, Global>

source§

impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GSList> for Twhere T: GlibPtrDefault + FromGlibPtrNone<<T as GlibPtrDefault>::GlibType> + FromGlibPtrFull<<T as GlibPtrDefault>::GlibType>,

source§

impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GList> for Twhere T: GlibPtrDefault + FromGlibPtrNone<<T as GlibPtrDefault>::GlibType> + FromGlibPtrFull<<T as GlibPtrDefault>::GlibType>,

source§

unsafe fn from_glib_none_as_vec(ptr: *mut GList) -> Vec<T, Global>

source§

unsafe fn from_glib_container_as_vec(ptr: *mut GList) -> Vec<T, Global>

source§

unsafe fn from_glib_full_as_vec(ptr: *mut GList) -> Vec<T, Global>

source§

impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GPtrArray> for Twhere T: GlibPtrDefault + FromGlibPtrNone<<T as GlibPtrDefault>::GlibType> + FromGlibPtrFull<<T as GlibPtrDefault>::GlibType>,

source§

unsafe fn from_glib_none_as_vec(ptr: *mut GPtrArray) -> Vec<T, Global>

source§

unsafe fn from_glib_container_as_vec(ptr: *mut GPtrArray) -> Vec<T, Global>

source§

unsafe fn from_glib_full_as_vec(ptr: *mut GPtrArray) -> Vec<T, Global>

source§

impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GSList> for Twhere T: GlibPtrDefault + FromGlibPtrNone<<T as GlibPtrDefault>::GlibType> + FromGlibPtrFull<<T as GlibPtrDefault>::GlibType>,

source§

unsafe fn from_glib_none_as_vec(ptr: *mut GSList) -> Vec<T, Global>

source§

unsafe fn from_glib_container_as_vec(ptr: *mut GSList) -> Vec<T, Global>

source§

unsafe fn from_glib_full_as_vec(ptr: *mut GSList) -> Vec<T, Global>

source§

impl<T, U> Into<U> for Twhere 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 Twhere T: Into<Value>,

source§

impl<T> Property for Twhere T: HasParamSpec,

§

type Value = T

source§

impl<T> PropertyGet for Twhere T: HasParamSpec,

§

type Value = T

source§

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

source§

impl<T> StaticTypeExt for Twhere T: StaticType,

source§

fn ensure_type()

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

impl<T> ToOwned for Twhere T: Clone,

§

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 Twhere T: TransparentPtrType,

source§

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

§

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 Twhere T: for<'a> FromValue<'a> + StaticType + 'static,

source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

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 Twhere T: FromValue<'a, Checker = C>, C: ValueTypeChecker<Error = ValueTypeMismatchOrNoneError<E>>, E: Error + Send + 'static,