pub struct VariantType { /* private fields */ }Expand description
Describes Variant types.
The Variant type system (based on the D-Bus one) describes types with
“type strings”. VariantType is an owned immutable type string (you can
think of it as a Box<str> statically guaranteed to be a valid type
string), &VariantTy is a borrowed one (like &str).
.
Any type string of a container that contains an indefinite type is,
itself, an indefinite type. For example, the type string a*
(corresponding to G_VARIANT_TYPE_ARRAY) is an indefinite type
that is a supertype of every array type. (*s) is a supertype
of all tuples that contain exactly two items where the second
item is a string.
a{?*} is an indefinite type that is a supertype of all arrays
containing dictionary entries where the key is any basic type and
the value is any type at all. This is, by definition, a dictionary,
so this type string corresponds to G_VARIANT_TYPE_DICTIONARY. Note
that, due to the restriction that the key of a dictionary entry must
be a basic type, {**} is not a valid type string.
Implementations§
Source§impl VariantType
impl VariantType
Sourcepub fn new(type_string: &str) -> Result<VariantType, BoolError>
pub fn new(type_string: &str) -> Result<VariantType, BoolError>
Tries to create a VariantType from a string slice.
Returns Ok if the string is a valid type string, Err otherwise.
Creates a new [type@GLib.VariantType] corresponding to the type string given
by @type_string.
It is appropriate to call GLib::VariantType::free() on the return value.
It is a programmer error to call this function with an invalid type
string. Use [string_is_valid()][Self::string_is_valid()] if you are unsure.
§type_string
a valid GVariant type string
§Returns
a new [type@GLib.VariantType]
Sourcepub fn new_dict_entry(
key_type: &VariantTy,
value_type: &VariantTy,
) -> VariantType
pub fn new_dict_entry( key_type: &VariantTy, value_type: &VariantTy, ) -> VariantType
Creates a VariantType from a key and value type.
Constructs the type corresponding to a dictionary entry with a key
of type @key and a value of type @value.
It is appropriate to call GLib::VariantType::free() on the return value.
§key
a basic type to use for the key
§value
a type to use for the value
§Returns
a new dictionary entry type Since 2.24
Sourcepub fn new_array(elem_type: &VariantTy) -> VariantType
pub fn new_array(elem_type: &VariantTy) -> VariantType
Sourcepub fn new_maybe(child_type: &VariantTy) -> VariantType
pub fn new_maybe(child_type: &VariantTy) -> VariantType
Sourcepub fn new_tuple(
items: impl IntoIterator<Item = impl AsRef<VariantTy>>,
) -> VariantType
pub fn new_tuple( items: impl IntoIterator<Item = impl AsRef<VariantTy>>, ) -> VariantType
Creates a VariantType from a maybe element type.
Constructs a new tuple type, from @items.
@length is the number of items in @items, or -1 to indicate that
@items is NULL-terminated.
It is appropriate to call GLib::VariantType::free() on the return value.
§items
an array of types, one for each item
§Returns
a new tuple type Since 2.24
Sourcepub fn from_string(
type_string: impl Into<GString>,
) -> Result<VariantType, BoolError>
pub fn from_string( type_string: impl Into<GString>, ) -> Result<VariantType, BoolError>
Tries to create a VariantType from an owned string.
Returns Ok if the string is a valid type string, Err otherwise.
Methods from Deref<Target = VariantTy>§
pub const BOOLEAN: &'static VariantTy
pub const BYTE: &'static VariantTy
pub const INT16: &'static VariantTy
pub const UINT16: &'static VariantTy
pub const INT32: &'static VariantTy
pub const UINT32: &'static VariantTy
pub const INT64: &'static VariantTy
pub const UINT64: &'static VariantTy
pub const DOUBLE: &'static VariantTy
pub const STRING: &'static VariantTy
pub const OBJECT_PATH: &'static VariantTy
pub const SIGNATURE: &'static VariantTy
pub const VARIANT: &'static VariantTy
pub const HANDLE: &'static VariantTy
pub const UNIT: &'static VariantTy
pub const ANY: &'static VariantTy
pub const BASIC: &'static VariantTy
pub const MAYBE: &'static VariantTy
pub const ARRAY: &'static VariantTy
pub const TUPLE: &'static VariantTy
pub const DICT_ENTRY: &'static VariantTy
pub const DICTIONARY: &'static VariantTy
pub const STRING_ARRAY: &'static VariantTy
pub const OBJECT_PATH_ARRAY: &'static VariantTy
pub const BYTE_STRING: &'static VariantTy
pub const BYTE_STRING_ARRAY: &'static VariantTy
pub const VARDICT: &'static VariantTy
Sourcepub fn is_definite(&self) -> bool
pub fn is_definite(&self) -> bool
Check if this variant type is a definite type.
Sourcepub fn is_container(&self) -> bool
pub fn is_container(&self) -> bool
Check if this variant type is a container type.
Sourcepub fn is_dict_entry(&self) -> bool
pub fn is_dict_entry(&self) -> bool
Check if this variant type is a dict entry type.
Sourcepub fn is_variant(&self) -> bool
pub fn is_variant(&self) -> bool
Check if this variant type is a variant.
Sourcepub fn is_subtype_of(&self, supertype: &Self) -> bool
pub fn is_subtype_of(&self, supertype: &Self) -> bool
Check if this variant type is a subtype of another.
Sourcepub fn element(&self) -> &VariantTy
pub fn element(&self) -> &VariantTy
Return the element type of this variant type.
§Panics
This function panics if not called with an array or maybe type.
Sourcepub fn tuple_types(&self) -> VariantTyIterator<'_> ⓘ
pub fn tuple_types(&self) -> VariantTyIterator<'_> ⓘ
Iterate over the types of this variant type.
§Panics
This function panics if not called with a tuple or dictionary entry type.
Sourcepub fn first(&self) -> Option<&VariantTy>
pub fn first(&self) -> Option<&VariantTy>
Return the first type of this variant type.
§Panics
This function panics if not called with a tuple or dictionary entry type.
Trait Implementations§
Source§impl AsRef<VariantTy> for VariantType
impl AsRef<VariantTy> for VariantType
Source§impl Borrow<VariantTy> for VariantType
impl Borrow<VariantTy> for VariantType
Source§impl Clone for VariantType
impl Clone for VariantType
Source§fn clone(&self) -> VariantType
fn clone(&self) -> VariantType
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for VariantType
impl Debug for VariantType
Source§impl Deref for VariantType
impl Deref for VariantType
Source§impl Display for VariantType
impl Display for VariantType
Source§impl Drop for VariantType
impl Drop for VariantType
impl Eq for VariantType
Source§impl FromStr for VariantType
impl FromStr for VariantType
Source§impl Hash for VariantType
impl Hash for VariantType
Source§impl PartialEq for VariantType
impl PartialEq for VariantType
Source§impl<'a, 'b> PartialEq<&'a VariantTy> for VariantType
impl<'a, 'b> PartialEq<&'a VariantTy> for VariantType
Source§impl<'a, 'b> PartialEq<&'a str> for VariantType
impl<'a, 'b> PartialEq<&'a str> for VariantType
Source§impl<'a, 'b> PartialEq<Cow<'a, VariantTy>> for VariantType
impl<'a, 'b> PartialEq<Cow<'a, VariantTy>> for VariantType
Source§impl<'a, 'b> PartialEq<String> for VariantType
impl<'a, 'b> PartialEq<String> for VariantType
Source§impl<'a, 'b> PartialEq<VariantTy> for VariantType
impl<'a, 'b> PartialEq<VariantTy> for VariantType
Source§impl<'a, 'b> PartialEq<VariantType> for VariantTy
impl<'a, 'b> PartialEq<VariantType> for VariantTy
Source§fn eq(&self, other: &VariantType) -> bool
fn eq(&self, other: &VariantType) -> bool
self and other values to be equal, and is used by ==.Source§impl<'a, 'b> PartialEq<VariantType> for &'a VariantTy
impl<'a, 'b> PartialEq<VariantType> for &'a VariantTy
Source§fn eq(&self, other: &VariantType) -> bool
fn eq(&self, other: &VariantType) -> bool
self and other values to be equal, and is used by ==.Source§impl<'a, 'b> PartialEq<VariantType> for Cow<'a, VariantTy>
impl<'a, 'b> PartialEq<VariantType> for Cow<'a, VariantTy>
Source§fn eq(&self, other: &VariantType) -> bool
fn eq(&self, other: &VariantType) -> bool
self and other values to be equal, and is used by ==.Source§impl<'a, 'b> PartialEq<VariantType> for str
impl<'a, 'b> PartialEq<VariantType> for str
Source§fn eq(&self, other: &VariantType) -> bool
fn eq(&self, other: &VariantType) -> bool
self and other values to be equal, and is used by ==.Source§impl<'a, 'b> PartialEq<VariantType> for &'a str
impl<'a, 'b> PartialEq<VariantType> for &'a str
Source§fn eq(&self, other: &VariantType) -> bool
fn eq(&self, other: &VariantType) -> bool
self and other values to be equal, and is used by ==.Source§impl<'a, 'b> PartialEq<VariantType> for String
impl<'a, 'b> PartialEq<VariantType> for String
Source§fn eq(&self, other: &VariantType) -> bool
fn eq(&self, other: &VariantType) -> bool
self and other values to be equal, and is used by ==.Source§impl<'a, 'b> PartialEq<str> for VariantType
impl<'a, 'b> PartialEq<str> for VariantType
impl Send for VariantType
Source§impl StaticType for VariantType
impl StaticType for VariantType
Source§fn static_type() -> Type
fn static_type() -> Type
Self.impl Sync for VariantType
Auto Trait Implementations§
impl Freeze for VariantType
impl RefUnwindSafe for VariantType
impl Unpin for VariantType
impl UnsafeUnpin for VariantType
impl UnwindSafe for VariantType
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<'a, T, C, E> FromValueOptional<'a> for Twhere
T: FromValue<'a, Checker = C>,
C: ValueTypeChecker<Error = ValueTypeMismatchOrNoneError<E>>,
E: Error + Send + 'static,
Source§impl<T> IntoClosureReturnValue for T
impl<T> IntoClosureReturnValue for T
fn into_closure_return_value(self) -> Option<Value>
Source§impl<T> StaticTypeExt for Twhere
T: StaticType,
impl<T> StaticTypeExt for Twhere
T: StaticType,
Source§fn ensure_type()
fn ensure_type()
Source§impl<T> ToSendValue for T
impl<T> ToSendValue for T
Source§fn to_send_value(&self) -> SendValue
fn to_send_value(&self) -> SendValue
SendValue clone of self.