Struct VariantDict
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§
§impl VariantDict
impl VariantDict
pub fn as_ptr(&self) -> *mut GVariantDict
pub fn as_ptr(&self) -> *mut GVariantDict
Return the inner pointer to the underlying C value.
pub unsafe fn from_glib_ptr_borrow(ptr: &*mut GVariantDict) -> &VariantDict
pub unsafe fn from_glib_ptr_borrow(ptr: &*mut GVariantDict) -> &VariantDict
Borrows the underlying C value.
§impl VariantDict
impl VariantDict
pub fn new(from_asv: Option<&Variant>) -> VariantDict
pub fn new(from_asv: Option<&Variant>) -> VariantDict
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
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.
pub fn lookup<T>(
&self,
key: &str,
) -> Result<Option<T>, VariantTypeMismatchError>where
T: FromVariant,
pub fn lookup<T>(
&self,
key: &str,
) -> Result<Option<T>, VariantTypeMismatchError>where
T: FromVariant,
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.
pub fn lookup_value(
&self,
key: &str,
expected_type: Option<&VariantTy>,
) -> Option<Variant>
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.
pub fn insert_value(&self, key: &str, value: &Variant)
pub fn insert_value(&self, key: &str, value: &Variant)
pub fn insert(&self, key: &str, value: impl Into<Variant>)
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.
pub fn remove(&self, key: &str) -> bool
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.
pub unsafe fn end_unsafe(&self) -> Variant
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
pub fn end(&self) -> Variant
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§
§impl Clone for VariantDict
impl Clone for VariantDict
§fn clone(&self) -> VariantDict
fn clone(&self) -> VariantDict
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)
fn clone_from(&mut self, source: &Self)
source. Read more§impl Default for VariantDict
impl Default for VariantDict
§fn default() -> VariantDict
fn default() -> VariantDict
§impl From<Variant> for VariantDict
impl From<Variant> for VariantDict
§fn from(other: Variant) -> VariantDict
fn from(other: Variant) -> VariantDict
§impl From<VariantDict> for Value
impl From<VariantDict> for Value
§fn from(s: VariantDict) -> Value
fn from(s: VariantDict) -> Value
§impl From<VariantDict> for Variant
impl From<VariantDict> for Variant
§fn from(d: VariantDict) -> Variant
fn from(d: VariantDict) -> Variant
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.
§impl FromVariant for VariantDict
impl FromVariant for VariantDict
§fn from_variant(variant: &Variant) -> Option<VariantDict>
fn from_variant(variant: &Variant) -> Option<VariantDict>
§impl HasParamSpec for VariantDict
impl HasParamSpec for VariantDict
type ParamSpec = ParamSpecBoxed
§type SetValue = VariantDict
type SetValue = VariantDict
type BuilderFn = fn(&str) -> ParamSpecBoxedBuilder<'_, VariantDict>
fn param_spec_builder() -> <VariantDict as HasParamSpec>::BuilderFn
§impl StaticType for VariantDict
impl StaticType for VariantDict
§fn static_type() -> Type
fn static_type() -> Type
Self.§impl StaticVariantType for VariantDict
impl StaticVariantType for VariantDict
§fn static_variant_type() -> Cow<'static, VariantTy>
fn static_variant_type() -> Cow<'static, VariantTy>
VariantType corresponding to Self.§impl ToVariant for VariantDict
impl ToVariant for VariantDict
§fn to_variant(&self) -> Variant
fn to_variant(&self) -> Variant
Variant clone of self.Auto Trait Implementations§
impl Freeze for VariantDict
impl RefUnwindSafe for VariantDict
impl !Send for VariantDict
impl !Sync for VariantDict
impl Unpin for VariantDict
impl UnwindSafe for VariantDict
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GList> for Twhere
T: GlibPtrDefault + FromGlibPtrNone<<T as GlibPtrDefault>::GlibType> + FromGlibPtrFull<<T as GlibPtrDefault>::GlibType>,
impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GList> for Twhere
T: GlibPtrDefault + FromGlibPtrNone<<T as GlibPtrDefault>::GlibType> + FromGlibPtrFull<<T as GlibPtrDefault>::GlibType>,
§impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GPtrArray> for Twhere
T: GlibPtrDefault + FromGlibPtrNone<<T as GlibPtrDefault>::GlibType> + FromGlibPtrFull<<T as GlibPtrDefault>::GlibType>,
impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GPtrArray> for Twhere
T: GlibPtrDefault + FromGlibPtrNone<<T as GlibPtrDefault>::GlibType> + FromGlibPtrFull<<T as GlibPtrDefault>::GlibType>,
§impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GSList> for Twhere
T: GlibPtrDefault + FromGlibPtrNone<<T as GlibPtrDefault>::GlibType> + FromGlibPtrFull<<T as GlibPtrDefault>::GlibType>,
impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GSList> for Twhere
T: GlibPtrDefault + FromGlibPtrNone<<T as GlibPtrDefault>::GlibType> + FromGlibPtrFull<<T as GlibPtrDefault>::GlibType>,
§impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GList> for Twhere
T: GlibPtrDefault + FromGlibPtrNone<<T as GlibPtrDefault>::GlibType> + FromGlibPtrFull<<T as GlibPtrDefault>::GlibType>,
impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GList> for Twhere
T: GlibPtrDefault + FromGlibPtrNone<<T as GlibPtrDefault>::GlibType> + FromGlibPtrFull<<T as GlibPtrDefault>::GlibType>,
§impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GPtrArray> for Twhere
T: GlibPtrDefault + FromGlibPtrNone<<T as GlibPtrDefault>::GlibType> + FromGlibPtrFull<<T as GlibPtrDefault>::GlibType>,
impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GPtrArray> for Twhere
T: GlibPtrDefault + FromGlibPtrNone<<T as GlibPtrDefault>::GlibType> + FromGlibPtrFull<<T as GlibPtrDefault>::GlibType>,
§impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GSList> for Twhere
T: GlibPtrDefault + FromGlibPtrNone<<T as GlibPtrDefault>::GlibType> + FromGlibPtrFull<<T as GlibPtrDefault>::GlibType>,
impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GSList> for Twhere
T: GlibPtrDefault + FromGlibPtrNone<<T as GlibPtrDefault>::GlibType> + FromGlibPtrFull<<T as GlibPtrDefault>::GlibType>,
§impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GList> for Twhere
T: GlibPtrDefault + FromGlibPtrNone<<T as GlibPtrDefault>::GlibType> + FromGlibPtrFull<<T as GlibPtrDefault>::GlibType>,
impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GList> for Twhere
T: GlibPtrDefault + FromGlibPtrNone<<T as GlibPtrDefault>::GlibType> + FromGlibPtrFull<<T as GlibPtrDefault>::GlibType>,
unsafe fn from_glib_none_as_vec(ptr: *const GList) -> Vec<T>
unsafe fn from_glib_container_as_vec(_: *const GList) -> Vec<T>
unsafe fn from_glib_full_as_vec(_: *const GList) -> Vec<T>
§impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GPtrArray> for Twhere
T: GlibPtrDefault + FromGlibPtrNone<<T as GlibPtrDefault>::GlibType> + FromGlibPtrFull<<T as GlibPtrDefault>::GlibType>,
impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GPtrArray> for Twhere
T: GlibPtrDefault + FromGlibPtrNone<<T as GlibPtrDefault>::GlibType> + FromGlibPtrFull<<T as GlibPtrDefault>::GlibType>,
unsafe fn from_glib_none_as_vec(ptr: *const GPtrArray) -> Vec<T>
unsafe fn from_glib_container_as_vec(_: *const GPtrArray) -> Vec<T>
unsafe fn from_glib_full_as_vec(_: *const GPtrArray) -> Vec<T>
§impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GSList> for Twhere
T: GlibPtrDefault + FromGlibPtrNone<<T as GlibPtrDefault>::GlibType> + FromGlibPtrFull<<T as GlibPtrDefault>::GlibType>,
impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GSList> for Twhere
T: GlibPtrDefault + FromGlibPtrNone<<T as GlibPtrDefault>::GlibType> + FromGlibPtrFull<<T as GlibPtrDefault>::GlibType>,
unsafe fn from_glib_none_as_vec(ptr: *const GSList) -> Vec<T>
unsafe fn from_glib_container_as_vec(_: *const GSList) -> Vec<T>
unsafe fn from_glib_full_as_vec(_: *const GSList) -> Vec<T>
§impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GList> for Twhere
T: GlibPtrDefault + FromGlibPtrNone<<T as GlibPtrDefault>::GlibType> + FromGlibPtrFull<<T as GlibPtrDefault>::GlibType>,
impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GList> for Twhere
T: GlibPtrDefault + FromGlibPtrNone<<T as GlibPtrDefault>::GlibType> + FromGlibPtrFull<<T as GlibPtrDefault>::GlibType>,
unsafe fn from_glib_none_as_vec(ptr: *mut GList) -> Vec<T>
unsafe fn from_glib_container_as_vec(ptr: *mut GList) -> Vec<T>
unsafe fn from_glib_full_as_vec(ptr: *mut GList) -> Vec<T>
§impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GPtrArray> for Twhere
T: GlibPtrDefault + FromGlibPtrNone<<T as GlibPtrDefault>::GlibType> + FromGlibPtrFull<<T as GlibPtrDefault>::GlibType>,
impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GPtrArray> for Twhere
T: GlibPtrDefault + FromGlibPtrNone<<T as GlibPtrDefault>::GlibType> + FromGlibPtrFull<<T as GlibPtrDefault>::GlibType>,
unsafe fn from_glib_none_as_vec(ptr: *mut GPtrArray) -> Vec<T>
unsafe fn from_glib_container_as_vec(ptr: *mut GPtrArray) -> Vec<T>
unsafe fn from_glib_full_as_vec(ptr: *mut GPtrArray) -> Vec<T>
§impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GSList> for Twhere
T: GlibPtrDefault + FromGlibPtrNone<<T as GlibPtrDefault>::GlibType> + FromGlibPtrFull<<T as GlibPtrDefault>::GlibType>,
impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GSList> for Twhere
T: GlibPtrDefault + FromGlibPtrNone<<T as GlibPtrDefault>::GlibType> + FromGlibPtrFull<<T as GlibPtrDefault>::GlibType>,
unsafe fn from_glib_none_as_vec(ptr: *mut GSList) -> Vec<T>
unsafe fn from_glib_container_as_vec(ptr: *mut GSList) -> Vec<T>
unsafe fn from_glib_full_as_vec(ptr: *mut GSList) -> Vec<T>
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
§impl<T> IntoClosureReturnValue for T
impl<T> IntoClosureReturnValue for T
fn into_closure_return_value(self) -> Option<Value>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more