pub struct VariantDict { /* private fields */ }
Expand description
VariantDict
is a mutable key/value store where the keys are always
strings and the values are Variant
s.
Variant dictionaries can easily be converted to/from Variant
s 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
impl VariantDict
Sourcepub fn as_ptr(&self) -> *mut GVariantDict
pub fn as_ptr(&self) -> *mut GVariantDict
Return the inner pointer to the underlying C value.
Sourcepub unsafe fn from_glib_ptr_borrow(ptr: &*mut GVariantDict) -> &Self
pub unsafe fn from_glib_ptr_borrow(ptr: &*mut GVariantDict) -> &Self
Borrows the underlying C value.
Source§impl VariantDict
impl VariantDict
Sourcepub fn new(from_asv: Option<&Variant>) -> Self
pub fn new(from_asv: Option<&Variant>) -> Self
Create a new VariantDict
optionally populating it with the given Variant
Since Variant
s 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.
Sourcepub 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
.
Sourcepub fn lookup<T: FromVariant>(
&self,
key: &str,
) -> Result<Option<T>, VariantTypeMismatchError>
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.
Sourcepub 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
.
Sourcepub fn insert_value(&self, key: &str, value: &Variant)
pub fn insert_value(&self, key: &str, value: &Variant)
Sourcepub 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.
Sourcepub 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.
Sourcepub 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
Sourcepub 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§
Source§impl Clone for VariantDict
impl Clone for VariantDict
Source§impl Default for VariantDict
impl Default for VariantDict
Source§impl From<Variant> for VariantDict
impl From<Variant> for VariantDict
Source§impl From<VariantDict> for Value
impl From<VariantDict> for Value
Source§fn from(s: VariantDict) -> Self
fn from(s: VariantDict) -> Self
Source§impl From<VariantDict> for Variant
impl From<VariantDict> for Variant
Source§fn from(d: VariantDict) -> Self
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
impl FromVariant for VariantDict
Source§impl HasParamSpec for VariantDict
impl HasParamSpec for VariantDict
type ParamSpec = ParamSpecBoxed
Source§type SetValue = VariantDict
type SetValue = VariantDict
type BuilderFn = fn(_: &str) -> ParamSpecBoxedBuilder<'_, VariantDict>
fn param_spec_builder() -> Self::BuilderFn
Source§impl StaticType for VariantDict
impl StaticType for VariantDict
Source§fn static_type() -> Type
fn static_type() -> Type
Self
.Source§impl StaticVariantType for VariantDict
impl StaticVariantType for VariantDict
Source§fn static_variant_type() -> Cow<'static, VariantTy>
fn static_variant_type() -> Cow<'static, VariantTy>
VariantType
corresponding to Self
.Source§impl ToVariant for VariantDict
impl ToVariant for VariantDict
Source§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,
Source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)