#[repr(transparent)]pub struct Variant { /* private fields */ }
Expand description
A generic immutable value capable of carrying various types.
See the module documentation for more details.
Implementations
Returns true
if the type of the value corresponds to T
.
Returns the classification of the variant.
Tries to extract a value of type T
.
Returns Some
if T
matches the variant’s type.
Tries to extract a value of type T
.
Boxes value.
Unboxes self.
Returns Some
if self contains a Variant
.
Reads a child item out of a container Variant
instance.
Panics
- if
self
is not a container type. - if given
index
is larger than number of children.
Try to read a child item out of a container Variant
instance.
It returns None
if self
is not a container type or if the given
index
is larger than number of children.
pub fn try_child_get<T: StaticVariantType + FromVariant>(
&self,
index: usize
) -> Result<Option<T>, VariantTypeMismatchError>
pub fn try_child_get<T: StaticVariantType + FromVariant>(
&self,
index: usize
) -> Result<Option<T>, VariantTypeMismatchError>
Try to read a child item out of a container Variant
instance.
It returns Ok(None)
if self
is not a container type or if the given
index
is larger than number of children. An error is thrown if the
type does not match.
Read a child item out of a container Variant
instance.
Panics
- if
self
is not a container type. - if given
index
is larger than number of children. - if the expected variant type does not match
Tries to extract a &str
.
Returns Some
if the variant has a string type (s
, o
or g
type
strings).
Tries to extract a &[T]
from a variant of array type with a suitable element type.
Returns an error if the type is wrong.
pub fn array_from_iter<T: StaticVariantType, I: IntoIterator<Item = Variant>>(
children: I
) -> Self
pub fn array_from_iter<T: StaticVariantType, I: IntoIterator<Item = Variant>>(
children: I
) -> Self
Creates a new Variant array from children.
Panics
This function panics if not all variants are of type T
.
Creates a new Variant array from a fixed array.
Creates a new Variant tuple from children.
Creates a new maybe Variant.
Constructs a new serialized-mode GVariant instance.
Constructs a new serialized-mode GVariant instance.
This is the same as from_bytes
, except that checks on the passed
data are skipped.
You should not use this function on data from external sources.
Safety
Since the data is not validated, this is potentially dangerous if called on bytes which are not guaranteed to have come from serialising another Variant. The caller is responsible for ensuring bad data is not passed in.
Constructs a new serialized-mode GVariant instance.
Constructs a new serialized-mode GVariant instance.
This is the same as from_data
, except that checks on the passed
data are skipped.
You should not use this function on data from external sources.
Safety
Since the data is not validated, this is potentially dangerous if called on bytes which are not guaranteed to have come from serialising another Variant. The caller is responsible for ensuring bad data is not passed in.
Constructs a new serialized-mode GVariant instance with a given type.
Constructs a new serialized-mode GVariant instance with a given type.
This is the same as from_bytes
, except that checks on the passed
data are skipped.
You should not use this function on data from external sources.
Safety
Since the data is not validated, this is potentially dangerous if called on bytes which are not guaranteed to have come from serialising another Variant. The caller is responsible for ensuring bad data is not passed in.
Constructs a new serialized-mode GVariant instance with a given type.
Constructs a new serialized-mode GVariant instance with a given type.
This is the same as from_data
, except that checks on the passed
data are skipped.
You should not use this function on data from external sources.
Safety
Since the data is not validated, this is potentially dangerous if called on bytes which are not guaranteed to have come from serialising another Variant. The caller is responsible for ensuring bad data is not passed in.
Returns the serialized form of a GVariant instance.
Returns the serialized form of a GVariant instance.
Stores the serialized form of a GVariant instance into the given slice.
The slice needs to be big enough.
Returns a copy of the variant in normal form.
Determines the number of children in a container GVariant instance.
pub fn iter(&self) -> VariantIterⓘNotable traits for VariantIterimpl Iterator for VariantIter type Item = Variant;
pub fn iter(&self) -> VariantIterⓘNotable traits for VariantIterimpl Iterator for VariantIter type Item = Variant;
impl Iterator for VariantIter type Item = Variant;
Create an iterator over items in the variant.
Note that this heap allocates a variant for each element, which can be particularly expensive for large arrays.
Create an iterator over borrowed strings from a GVariant of type as
(array of string).
This will fail if the variant is not an array of with the expected child type.
A benefit of this API over Self::iter()
is that it
minimizes allocation, and provides strongly typed access.
let strs = &["foo", "bar"];
let strs_variant: glib::Variant = strs.to_variant();
for s in strs_variant.array_iter_str()? {
println!("{}", s);
}
Variant has a container type.
Trait Implementations
Creates a value from an iterator. Read more
Tries to extract a value. Read more
This method returns an ordering between self
and other
values if one exists. Read more
This method tests less than (for self
and other
) and is used by the <
operator. Read more
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
Returns the type identifier of Self
.
Returns the VariantType
corresponding to Self
.
Returns a Variant
clone of self
.
Auto Trait Implementations
Blanket Implementations
Mutably borrows from an owned value. Read more
Returns a SendValue
clone of self
.