Struct glib::variant::Variant

source ·
pub struct Variant { /* private fields */ }
Expand description

A generic immutable value capable of carrying various types.

See the module documentation for more details. Variant is a variant datatype; it can contain one or more values along with information about the type of the values.

A Variant may contain simple types, like an integer, or a boolean value; or complex types, like an array of two strings, or a dictionary of key value pairs. A Variant is also immutable: once it’s been created neither its type nor its content can be modified further.

GVariant is useful whenever data needs to be serialized, for example when sending method parameters in D-Bus, or when saving settings using GSettings.

When creating a new Variant, you pass the data you want to store in it along with a string representing the type of data you wish to pass to it.

For instance, if you want to create a Variant holding an integer value you can use:

⚠️ The following code is in C ⚠️

  GVariant *v = g_variant_new ("u", 40);

The string “u” in the first argument tells Variant that the data passed to the constructor (40) is going to be an unsigned integer.

More advanced examples of Variant in use can be found in documentation for [GVariant format strings][gvariant-format-strings-pointers].

The range of possible values is determined by the type.

The type system used by Variant is VariantType.

Variant instances always have a type and a value (which are given at construction time). The type and value of a Variant instance can never change other than by the Variant itself being destroyed. A Variant cannot contain a pointer.

Variant is reference counted using g_variant_ref() and g_variant_unref(). Variant also has floating reference counts – see [ref_sink()][Self::ref_sink()].

Variant is completely threadsafe. A Variant instance can be concurrently accessed in any way from any number of threads without problems.

Variant is heavily optimised for dealing with data in serialized form. It works particularly well with data located in memory-mapped files. It can perform nearly all deserialization operations in a small constant time, usually touching only a single memory page. Serialized Variant data can also be sent over the network.

Variant is largely compatible with D-Bus. Almost all types of Variant instances can be sent over D-Bus. See VariantType for exceptions. (However, Variant’s serialization format is not the same as the serialization format of a D-Bus message body: use GDBusMessage, in the gio library, for those.)

For space-efficiency, the Variant serialization format does not automatically include the variant’s length, type or endianness, which must either be implied from context (such as knowledge that a particular file format always contains a little-endian G_VARIANT_TYPE_VARIANT which occupies the whole length of the file) or supplied out-of-band (for instance, a length, type and/or endianness indicator could be placed at the beginning of a file, network message or network stream).

A Variant’s size is limited mainly by any lower level operating system constraints, such as the number of bits in gsize. For example, it is reasonable to have a 2GB file mapped into memory with GMappedFile, and call from_data() on it.

For convenience to C programmers, Variant features powerful varargs-based value construction and destruction. This feature is designed to be embedded in other libraries.

There is a Python-inspired text language for describing Variant values. Variant includes a printer for this language and a parser with type inferencing.

Memory Use

Variant tries to be quite efficient with respect to memory use. This section gives a rough idea of how much memory is used by the current implementation. The information here is subject to change in the future.

The memory allocated by Variant can be grouped into 4 broad purposes: memory for serialized data, memory for the type information cache, buffer management memory and memory for the Variant structure itself.

Serialized Data Memory

This is the memory that is used for storing GVariant data in serialized form. This is what would be sent over the network or what would end up on disk, not counting any indicator of the endianness, or of the length or type of the top-level variant.

The amount of memory required to store a boolean is 1 byte. 16, 32 and 64 bit integers and double precision floating point numbers use their “natural” size. Strings (including object path and signature strings) are stored with a nul terminator, and as such use the length of the string plus 1 byte.

Maybe types use no space at all to represent the null value and use the same amount of space (sometimes plus one byte) as the equivalent non-maybe-typed value to represent the non-null case.

Arrays use the amount of space required to store each of their members, concatenated. Additionally, if the items stored in an array are not of a fixed-size (ie: strings, other arrays, etc) then an additional framing offset is stored for each item. The size of this offset is either 1, 2 or 4 bytes depending on the overall size of the container. Additionally, extra padding bytes are added as required for alignment of child values.

Tuples (including dictionary entries) use the amount of space required to store each of their members, concatenated, plus one framing offset (as per arrays) for each non-fixed-sized item in the tuple, except for the last one. Additionally, extra padding bytes are added as required for alignment of child values.

Variants use the same amount of space as the item inside of the variant, plus 1 byte, plus the length of the type string for the item inside the variant.

As an example, consider a dictionary mapping strings to variants. In the case that the dictionary is empty, 0 bytes are required for the serialization.

If we add an item “width” that maps to the int32 value of 500 then we will use 4 byte to store the int32 (so 6 for the variant containing it) and 6 bytes for the string. The variant must be aligned to 8 after the 6 bytes of the string, so that’s 2 extra bytes. 6 (string) + 2 (padding) + 6 (variant) is 14 bytes used for the dictionary entry. An additional 1 byte is added to the array as a framing offset making a total of 15 bytes.

If we add another entry, “title” that maps to a nullable string that happens to have a value of null, then we use 0 bytes for the null value (and 3 bytes for the variant to contain it along with its type string) plus 6 bytes for the string. Again, we need 2 padding bytes. That makes a total of 6 + 2 + 3 = 11 bytes.

We now require extra padding between the two items in the array. After the 14 bytes of the first item, that’s 2 bytes required. We now require 2 framing offsets for an extra two bytes. 14 + 2 + 11 + 2 = 29 bytes to encode the entire two-item dictionary.

Type Information Cache

For each GVariant type that currently exists in the program a type information structure is kept in the type information cache. The type information structure is required for rapid deserialization.

Continuing with the above example, if a Variant exists with the type “a{sv}” then a type information struct will exist for “a{sv}”, “{sv}”, “s”, and “v”. Multiple uses of the same type will share the same type information. Additionally, all single-digit types are stored in read-only static memory and do not contribute to the writable memory footprint of a program using Variant.

Aside from the type information structures stored in read-only memory, there are two forms of type information. One is used for container types where there is a single element type: arrays and maybe types. The other is used for container types where there are multiple element types: tuples and dictionary entries.

Array type info structures are 6 * sizeof (void *), plus the memory required to store the type string itself. This means that on 32-bit systems, the cache entry for “a{sv}” would require 30 bytes of memory (plus malloc overhead).

Tuple type info structures are 6 * sizeof (void *), plus 4 * sizeof (void *) for each item in the tuple, plus the memory required to store the type string itself. A 2-item tuple, for example, would have a type information structure that consumed writable memory in the size of 14 * sizeof (void *) (plus type string) This means that on 32-bit systems, the cache entry for “{sv}” would require 61 bytes of memory (plus malloc overhead).

This means that in total, for our “a{sv}” example, 91 bytes of type information would be allocated.

The type information cache, additionally, uses a GHashTable to store and look up the cached items and stores a pointer to this hash table in static storage. The hash table is freed when there are zero items in the type cache.

Although these sizes may seem large it is important to remember that a program will probably only have a very small number of different types of values in it and that only one type information structure is required for many different values of the same type.

Buffer Management Memory

Variant uses an internal buffer management structure to deal with the various different possible sources of serialized data that it uses. The buffer is responsible for ensuring that the correct call is made when the data is no longer in use by Variant. This may involve a g_free() or a g_slice_free() or even g_mapped_file_unref().

One buffer management structure is used for each chunk of serialized data. The size of the buffer management structure is 4 * (void *). On 32-bit systems, that’s 16 bytes.

GVariant structure

The size of a Variant structure is 6 * (void *). On 32-bit systems, that’s 24 bytes.

Variant structures only exist if they are explicitly created with API calls. For example, if a Variant is constructed out of serialized data for the example given above (with the dictionary) then although there are 9 individual values that comprise the entire dictionary (two keys, two values, two variants containing the values, two dictionary entries, plus the dictionary itself), only 1 Variant instance exists – the one referring to the dictionary.

If calls are made to start accessing the other values then Variant instances will exist for those values only for as long as they are in use (ie: until you call g_variant_unref()). The type information is shared. The serialized data and the buffer management structure for that serialized data is shared by the child.

Summary

To put the entire example together, for our dictionary mapping strings to variants (with two entries, as given above), we are using 91 bytes of memory for type information, 29 bytes of memory for the serialized data, 16 bytes for buffer management and 24 bytes for the Variant instance, or a total of 160 bytes, plus malloc overhead. If we were to use child_value() to access the two dictionary entries, we would use an additional 48 bytes. If we were to have other dictionaries of the same type, we would use more memory for the serialized data and buffer management for those dictionaries, but the type information would be shared.

Implementations§

source§

impl Variant

source

pub fn as_ptr(&self) -> *mut GVariant

Return the inner pointer to the underlying C value.

source

pub unsafe fn from_glib_ptr_borrow<'a>(ptr: *const *const GVariant) -> &'a Self

Borrows the underlying C value.

source§

impl Variant

source

pub fn type_(&self) -> &VariantTy

Returns the type of the value. Determines the type of self.

The return value is valid for the lifetime of self and must not be freed.

Returns

a VariantType

source

pub fn is<T: StaticVariantType>(&self) -> bool

Returns true if the type of the value corresponds to T.

source

pub fn is_type(&self, type_: &VariantTy) -> bool

Returns true if the type of the value corresponds to type_.

This is equivalent to self.type_().is_subtype_of(type_).

source

pub fn classify(&self) -> VariantClass

Returns the classification of the variant. Classifies self according to its top-level type.

Returns

the VariantClass of self

source

pub fn get<T: FromVariant>(&self) -> Option<T>

Tries to extract a value of type T.

Returns Some if T matches the variant’s type. Deconstructs a Variant instance.

Think of this function as an analogue to scanf().

The arguments that are expected by this function are entirely determined by format_string. format_string also restricts the permissible types of self. It is an error to give a value with an incompatible type. See the section on [GVariant format strings][gvariant-format-strings]. Please note that the syntax of the format string is very likely to be extended in the future.

format_string determines the C types that are used for unpacking the values and also determines if the values are copied or borrowed, see the section on [GVariant format strings][gvariant-format-strings-pointers].

format_string

a Variant format string

source

pub fn try_get<T: FromVariant>(&self) -> Result<T, VariantTypeMismatchError>

Tries to extract a value of type T.

source

pub fn from_variant(value: &Variant) -> Self

Boxes value.

source

pub fn as_variant(&self) -> Option<Variant>

Unboxes self.

Returns Some if self contains a Variant.

source

pub fn child_value(&self, index: usize) -> 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. Reads a child item out of a container Variant instance. This includes variants, maybes, arrays, tuples and dictionary entries. It is an error to call this function on any other type of Variant.

It is an error if index_ is greater than the number of child items in the container. See n_children().

The returned value is never floating. You should free it with g_variant_unref() when you’re done with it.

Note that values borrowed from the returned child are not guaranteed to still be valid after the child is freed even if you still hold a reference to self, if self has not been serialized at the time this function is called. To avoid this, you can serialize self by calling data() and optionally ignoring the return value.

There may be implementation specific restrictions on deeply nested values, which would result in the unit tuple being returned as the child value, instead of further nested children. Variant is guaranteed to handle nesting up to at least 64 levels.

This function is O(1).

index_

the index of the child to fetch

Returns

the child at the specified index

source

pub fn try_child_value(&self, index: usize) -> Option<Variant>

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.

source

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.

source

pub fn child_get<T: StaticVariantType + FromVariant>(&self, index: usize) -> T

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
source

pub fn str(&self) -> Option<&str>

Tries to extract a &str.

Returns Some if the variant has a string type (s, o or g type strings).

source

pub fn fixed_array<T: FixedSizeVariantType>( &self ) -> Result<&[T], VariantTypeMismatchError>

Tries to extract a &[T] from a variant of array type with a suitable element type.

Returns an error if the type is wrong. Provides access to the serialized data for an array of fixed-sized items.

self must be an array with fixed-sized elements. Numeric types are fixed-size, as are tuples containing only other fixed-sized types.

element_size must be the size of a single element in the array, as given by the section on [serialized data memory][gvariant-serialized-data-memory].

In particular, arrays of these fixed-sized types can be interpreted as an array of the given C type, with element_size set to the size the appropriate type:

  • G_VARIANT_TYPE_INT16 (etc.): gint16 (etc.)
  • G_VARIANT_TYPE_BOOLEAN: guchar (not gboolean!)
  • G_VARIANT_TYPE_BYTE: guint8
  • G_VARIANT_TYPE_HANDLE: guint32
  • G_VARIANT_TYPE_DOUBLE: gdouble

For example, if calling this function for an array of 32-bit integers, you might say sizeof(gint32). This value isn’t used except for the purpose of a double-check that the form of the serialized data matches the caller’s expectation.

n_elements, which must be non-None, is set equal to the number of items in the array.

element_size

the size of each element

Returns

a pointer to the fixed array

source

pub fn array_from_iter<T: StaticVariantType>( children: impl IntoIterator<Item = Variant> ) -> Self

Creates a new Variant array from children.

Panics

This function panics if not all variants are of type T.

source

pub fn array_from_iter_with_type( type_: &VariantTy, children: impl IntoIterator<Item = impl AsRef<Variant>> ) -> Self

Creates a new Variant array from children with the specified type.

Panics

This function panics if not all variants are of type type_.

source

pub fn array_from_fixed_array<T: FixedSizeVariantType>(array: &[T]) -> Self

Creates a new Variant array from a fixed array.

source

pub fn tuple_from_iter( children: impl IntoIterator<Item = impl AsRef<Variant>> ) -> Self

Creates a new Variant tuple from children.

source

pub fn from_dict_entry(key: &Variant, value: &Variant) -> Self

Creates a new dictionary entry Variant.

DictEntry should be preferred over this when the types are known statically.

source

pub fn from_maybe<T: StaticVariantType>(child: Option<&Variant>) -> Self

Creates a new maybe Variant.

source

pub fn from_some(child: &Variant) -> Self

Creates a new maybe Variant from a child.

source

pub fn from_none(type_: &VariantTy) -> Self

Creates a new maybe Variant with Nothing.

source

pub fn as_maybe(&self) -> Option<Variant>

Extract the value of a maybe Variant.

Returns the child value, or None if the value is Nothing.

Panics

Panics if the variant is not maybe-typed.

source

pub fn print(&self, type_annotate: bool) -> GString

Pretty-print the contents of this variant in a human-readable form.

A variant can be recreated from this output via Variant::parse. Pretty-prints self in the format understood by g_variant_parse().

The format is described [here][gvariant-text].

If type_annotate is true, then type information is included in the output.

type_annotate

true if type information should be included in the output

Returns

a newly-allocated string holding the result.

source

pub fn parse(type_: Option<&VariantTy>, text: &str) -> Result<Self, Error>

Parses a GVariant from the text representation produced by print().

source

pub fn from_bytes<T: StaticVariantType>(bytes: &Bytes) -> Self

Constructs a new serialized-mode GVariant instance. Constructs a new serialized-mode Variant instance. This is the inner interface for creation of new serialized values that gets called from various functions in gvariant.c.

A reference is taken on bytes.

The data in bytes must be aligned appropriately for the type_ being loaded. Otherwise this function will internally create a copy of the memory (since GLib 2.60) or (in older versions) fail and exit the process.

type_

a VariantType

bytes

a Bytes

trusted

if the contents of bytes are trusted

Returns

a new Variant with a floating reference

source

pub unsafe fn from_bytes_trusted<T: StaticVariantType>(bytes: &Bytes) -> Self

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.

source

pub fn from_data<T: StaticVariantType, A: AsRef<[u8]>>(data: A) -> Self

Constructs a new serialized-mode GVariant instance. Creates a new Variant instance from serialized data.

type_ is the type of Variant instance that will be constructed. The interpretation of data depends on knowing the type.

data is not modified by this function and must remain valid with an unchanging value until such a time as notify is called with user_data. If the contents of data change before that time then the result is undefined.

If data is trusted to be serialized data in normal form then trusted should be true. This applies to serialized data created within this process or read from a trusted location on the disk (such as a file installed in /usr/lib alongside your application). You should set trusted to false if data is read from the network, a file in the user’s home directory, etc.

If data was not stored in this machine’s native endianness, any multi-byte numeric values in the returned variant will also be in non-native endianness. byteswap() can be used to recover the original values.

notify will be called with user_data when data is no longer needed. The exact time of this call is unspecified and might even be before this function returns.

Note: data must be backed by memory that is aligned appropriately for the type_ being loaded. Otherwise this function will internally create a copy of the memory (since GLib 2.60) or (in older versions) fail and exit the process.

type_

a definite VariantType

data

the serialized data

trusted

true if data is definitely in normal form

notify

function to call when data is no longer needed

Returns

a new floating Variant of type type_

source

pub unsafe fn from_data_trusted<T: StaticVariantType, A: AsRef<[u8]>>( data: A ) -> Self

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.

source

pub fn from_bytes_with_type(bytes: &Bytes, type_: &VariantTy) -> Self

Constructs a new serialized-mode GVariant instance with a given type.

source

pub unsafe fn from_bytes_with_type_trusted( bytes: &Bytes, type_: &VariantTy ) -> Self

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.

source

pub fn from_data_with_type<A: AsRef<[u8]>>(data: A, type_: &VariantTy) -> Self

Constructs a new serialized-mode GVariant instance with a given type.

source

pub unsafe fn from_data_with_type_trusted<A: AsRef<[u8]>>( data: A, type_: &VariantTy ) -> Self

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.

source

pub fn data_as_bytes(&self) -> Bytes

Returns the serialized form of a GVariant instance. Returns a pointer to the serialized form of a Variant instance. The semantics of this function are exactly the same as data(), except that the returned Bytes holds a reference to the variant data.

Returns

A new Bytes representing the variant data

source

pub fn data(&self) -> &[u8]

Returns the serialized form of a GVariant instance. Returns a pointer to the serialized form of a Variant instance. The returned data may not be in fully-normalised form if read from an untrusted source. The returned data must not be freed; it remains valid for as long as self exists.

If self is a fixed-sized value that was deserialized from a corrupted serialized container then None may be returned. In this case, the proper thing to do is typically to use the appropriate number of nul bytes in place of self. If self is not fixed-sized then None is never returned.

In the case that self is already in serialized form, this function is O(1). If the value is not already in serialized form, serialization occurs implicitly and is approximately O(n) in the size of the result.

To deserialize the data returned by this function, in addition to the serialized data, you must know the type of the Variant, and (if the machine might be different) the endianness of the machine that stored it. As a result, file formats or network messages that incorporate serialized GVariants must include this information either implicitly (for instance “the file always contains a G_VARIANT_TYPE_VARIANT and it is always in little-endian order”) or explicitly (by storing the type and/or endianness in addition to the serialized data).

Returns

the serialized form of self, or None

source

pub fn size(&self) -> usize

Returns the size of serialized form of a GVariant instance. Determines the number of bytes that would be required to store self with store().

If self has a fixed-sized type then this function always returned that fixed size.

In the case that self is already in serialized form or the size has already been calculated (ie: this function has been called before) then this function is O(1). Otherwise, the size is calculated, an operation which is approximately O(n) in the number of values involved.

Returns

the serialized size of self

source

pub fn store(&self, data: &mut [u8]) -> Result<usize, BoolError>

Stores the serialized form of a GVariant instance into the given slice.

The slice needs to be big enough. Stores the serialized form of self at data. data should be large enough. See size().

The stored data is in machine native byte order but may not be in fully-normalised form if read from an untrusted source. See normal_form() for a solution.

As with data(), to be able to deserialize the serialized variant successfully, its type and (if the destination machine might be different) its endianness must also be available.

This function is approximately O(n) in the size of data.

source

pub fn normal_form(&self) -> Self

Returns a copy of the variant in normal form. Gets a Variant instance that has the same value as self and is trusted to be in normal form.

If self is already trusted to be in normal form then a new reference to self is returned.

If self is not already trusted, then it is scanned to check if it is in normal form. If it is found to be in normal form then it is marked as trusted and a new reference to it is returned.

If self is found not to be in normal form then a new trusted Variant is created with the same value as self. The non-normal parts of self will be replaced with default values which are guaranteed to be in normal form.

It makes sense to call this function if you’ve received Variant data from untrusted sources and you want to ensure your serialized output is definitely in normal form.

If self is already in normal form, a new reference will be returned (which will be floating if self is floating). If it is not in normal form, the newly created Variant will be returned with a single non-floating reference. Typically, g_variant_take_ref() should be called on the return value from this function to guarantee ownership of a single non-floating reference to it.

Returns

a trusted Variant

source

pub fn byteswap(&self) -> Self

Returns a copy of the variant in the opposite endianness. Performs a byteswapping operation on the contents of self. The result is that all multi-byte numeric data contained in self is byteswapped. That includes 16, 32, and 64bit signed and unsigned integers as well as file handles and double precision floating point values.

This function is an identity mapping on any value that does not contain multi-byte numeric data. That include strings, booleans, bytes and containers containing only these things (recursively).

While this function can safely handle untrusted, non-normal data, it is recommended to check whether the input is in normal form beforehand, using is_normal_form(), and to reject non-normal inputs if your application can be strict about what inputs it rejects.

The returned value is always in normal form and is marked as trusted. A full, not floating, reference is returned.

Returns

the byteswapped form of self

source

pub fn n_children(&self) -> usize

Determines the number of children in a container GVariant instance. Determines the number of children in a container Variant instance. This includes variants, maybes, arrays, tuples and dictionary entries. It is an error to call this function on any other type of Variant.

For variants, the return value is always 1. For values with maybe types, it is always zero or one. For arrays, it is the length of the array. For tuples it is the number of tuple items (which depends only on the type). For dictionary entries, it is always 2

This function is O(1).

Returns

the number of children in the container

source

pub fn iter(&self) -> VariantIter

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.

source

pub fn array_iter_str( &self ) -> Result<VariantStrIter<'_>, VariantTypeMismatchError>

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);
}
source

pub fn is_container(&self) -> bool

Return whether this Variant is a container type. Checks if self is a container.

Returns

true if self is a container

source

pub fn is_normal_form(&self) -> bool

Return whether this Variant is in normal form. Checks if self is in normal form.

The main reason to do this is to detect if a given chunk of serialized data is in normal form: load the data into a Variant using from_data() and then use this function to check.

If self is found to be in normal form then it will be marked as being trusted. If the value was already marked as being trusted then this function will immediately return true.

There may be implementation specific restrictions on deeply nested values. GVariant is guaranteed to handle nesting up to at least 64 levels.

Returns

true if self is in normal form

source

pub fn is_object_path(string: &str) -> bool

Return whether input string is a valid VariantClass::ObjectPath. Determines if a given string is a valid D-Bus object path. You should ensure that a string is a valid D-Bus object path before passing it to [new_object_path()][Self::new_object_path()].

A valid object path starts with / followed by zero or more sequences of characters separated by / characters. Each sequence must contain only the characters [A-Z][a-z][0-9]_. No sequence (including the one following the final / character) may be empty.

string

a normal C nul-terminated string

Returns

true if string is a D-Bus object path

source

pub fn is_signature(string: &str) -> bool

Return whether input string is a valid VariantClass::Signature. Determines if a given string is a valid D-Bus type signature. You should ensure that a string is a valid D-Bus type signature before passing it to [new_signature()][Self::new_signature()].

D-Bus type signatures consist of zero or more definite VariantType strings in sequence.

string

a normal C nul-terminated string

Returns

true if string is a D-Bus type signature

Trait Implementations§

source§

impl AsRef<Variant> for Variant

source§

fn as_ref(&self) -> &Self

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl Clone for Variant

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 Debug for Variant

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Display for Variant

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<T: StaticVariantType + ToVariant> From<&[T]> for Variant

source§

fn from(s: &[T]) -> Self

Converts to this type from the input type.
source§

impl From<&OsStr> for Variant

source§

fn from(s: &OsStr) -> Self

Converts to this type from the input type.
source§

impl From<&Path> for Variant

source§

fn from(p: &Path) -> Self

Converts to this type from the input type.
source§

impl<'a, T: ?Sized + Into<Variant> + Clone> From<&'a T> for Variant

source§

fn from(v: &'a T) -> Self

Converts to this type from the input type.
source§

impl From<&str> for Variant

source§

fn from(s: &str) -> Self

Converts to this type from the input type.
source§

impl From<()> for Variant

source§

fn from(_: ()) -> Self

Converts to this type from the input type.
source§

impl<T0> From<(T0,)> for Variant
where T0: Into<Variant>,

source§

fn from(t: (T0,)) -> Self

Converts to this type from the input type.
source§

impl<T0, T1> From<(T0, T1)> for Variant
where T0: Into<Variant>, T1: Into<Variant>,

source§

fn from(t: (T0, T1)) -> Self

Converts to this type from the input type.
source§

impl<T0, T1, T2> From<(T0, T1, T2)> for Variant
where T0: Into<Variant>, T1: Into<Variant>, T2: Into<Variant>,

source§

fn from(t: (T0, T1, T2)) -> Self

Converts to this type from the input type.
source§

impl<T0, T1, T2, T3> From<(T0, T1, T2, T3)> for Variant
where T0: Into<Variant>, T1: Into<Variant>, T2: Into<Variant>, T3: Into<Variant>,

source§

fn from(t: (T0, T1, T2, T3)) -> Self

Converts to this type from the input type.
source§

impl<T0, T1, T2, T3, T4> From<(T0, T1, T2, T3, T4)> for Variant
where T0: Into<Variant>, T1: Into<Variant>, T2: Into<Variant>, T3: Into<Variant>, T4: Into<Variant>,

source§

fn from(t: (T0, T1, T2, T3, T4)) -> Self

Converts to this type from the input type.
source§

impl<T0, T1, T2, T3, T4, T5> From<(T0, T1, T2, T3, T4, T5)> for Variant
where T0: Into<Variant>, T1: Into<Variant>, T2: Into<Variant>, T3: Into<Variant>, T4: Into<Variant>, T5: Into<Variant>,

source§

fn from(t: (T0, T1, T2, T3, T4, T5)) -> Self

Converts to this type from the input type.
source§

impl<T0, T1, T2, T3, T4, T5, T6> From<(T0, T1, T2, T3, T4, T5, T6)> for Variant
where T0: Into<Variant>, T1: Into<Variant>, T2: Into<Variant>, T3: Into<Variant>, T4: Into<Variant>, T5: Into<Variant>, T6: Into<Variant>,

source§

fn from(t: (T0, T1, T2, T3, T4, T5, T6)) -> Self

Converts to this type from the input type.
source§

impl<T0, T1, T2, T3, T4, T5, T6, T7> From<(T0, T1, T2, T3, T4, T5, T6, T7)> for Variant
where T0: Into<Variant>, T1: Into<Variant>, T2: Into<Variant>, T3: Into<Variant>, T4: Into<Variant>, T5: Into<Variant>, T6: Into<Variant>, T7: Into<Variant>,

source§

fn from(t: (T0, T1, T2, T3, T4, T5, T6, T7)) -> Self

Converts to this type from the input type.
source§

impl<T0, T1, T2, T3, T4, T5, T6, T7, T8> From<(T0, T1, T2, T3, T4, T5, T6, T7, T8)> for Variant
where T0: Into<Variant>, T1: Into<Variant>, T2: Into<Variant>, T3: Into<Variant>, T4: Into<Variant>, T5: Into<Variant>, T6: Into<Variant>, T7: Into<Variant>, T8: Into<Variant>,

source§

fn from(t: (T0, T1, T2, T3, T4, T5, T6, T7, T8)) -> Self

Converts to this type from the input type.
source§

impl<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9> From<(T0, T1, T2, T3, T4, T5, T6, T7, T8, T9)> for Variant
where T0: Into<Variant>, T1: Into<Variant>, T2: Into<Variant>, T3: Into<Variant>, T4: Into<Variant>, T5: Into<Variant>, T6: Into<Variant>, T7: Into<Variant>, T8: Into<Variant>, T9: Into<Variant>,

source§

fn from(t: (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9)) -> Self

Converts to this type from the input type.
source§

impl<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10> From<(T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10)> for Variant
where T0: Into<Variant>, T1: Into<Variant>, T2: Into<Variant>, T3: Into<Variant>, T4: Into<Variant>, T5: Into<Variant>, T6: Into<Variant>, T7: Into<Variant>, T8: Into<Variant>, T9: Into<Variant>, T10: Into<Variant>,

source§

fn from(t: (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10)) -> Self

Converts to this type from the input type.
source§

impl<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11> From<(T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11)> for Variant
where T0: Into<Variant>, T1: Into<Variant>, T2: Into<Variant>, T3: Into<Variant>, T4: Into<Variant>, T5: Into<Variant>, T6: Into<Variant>, T7: Into<Variant>, T8: Into<Variant>, T9: Into<Variant>, T10: Into<Variant>, T11: Into<Variant>,

source§

fn from(t: (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11)) -> Self

Converts to this type from the input type.
source§

impl<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12> From<(T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12)> for Variant
where T0: Into<Variant>, T1: Into<Variant>, T2: Into<Variant>, T3: Into<Variant>, T4: Into<Variant>, T5: Into<Variant>, T6: Into<Variant>, T7: Into<Variant>, T8: Into<Variant>, T9: Into<Variant>, T10: Into<Variant>, T11: Into<Variant>, T12: Into<Variant>,

source§

fn from(t: (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12)) -> Self

Converts to this type from the input type.
source§

impl<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13> From<(T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13)> for Variant
where T0: Into<Variant>, T1: Into<Variant>, T2: Into<Variant>, T3: Into<Variant>, T4: Into<Variant>, T5: Into<Variant>, T6: Into<Variant>, T7: Into<Variant>, T8: Into<Variant>, T9: Into<Variant>, T10: Into<Variant>, T11: Into<Variant>, T12: Into<Variant>, T13: Into<Variant>,

source§

fn from(t: (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13)) -> Self

Converts to this type from the input type.
source§

impl<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14> From<(T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14)> for Variant
where T0: Into<Variant>, T1: Into<Variant>, T2: Into<Variant>, T3: Into<Variant>, T4: Into<Variant>, T5: Into<Variant>, T6: Into<Variant>, T7: Into<Variant>, T8: Into<Variant>, T9: Into<Variant>, T10: Into<Variant>, T11: Into<Variant>, T12: Into<Variant>, T13: Into<Variant>, T14: Into<Variant>,

source§

fn from( t: (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14) ) -> Self

Converts to this type from the input type.
source§

impl<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15> From<(T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15)> for Variant
where T0: Into<Variant>, T1: Into<Variant>, T2: Into<Variant>, T3: Into<Variant>, T4: Into<Variant>, T5: Into<Variant>, T6: Into<Variant>, T7: Into<Variant>, T8: Into<Variant>, T9: Into<Variant>, T10: Into<Variant>, T11: Into<Variant>, T12: Into<Variant>, T13: Into<Variant>, T14: Into<Variant>, T15: Into<Variant>,

source§

fn from( t: (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15) ) -> Self

Converts to this type from the input type.
source§

impl<K, V> From<BTreeMap<K, V>> for Variant

source§

fn from(m: BTreeMap<K, V>) -> Self

Converts to this type from the input type.
source§

impl<K, V> From<DictEntry<K, V>> for Variant

source§

fn from(e: DictEntry<K, V>) -> Self

Converts to this type from the input type.
source§

impl<A: AsRef<[T]>, T: FixedSizeVariantType> From<FixedSizeVariantArray<A, T>> for Variant

source§

fn from(a: FixedSizeVariantArray<A, T>) -> Self

Converts to this type from the input type.
source§

impl From<Handle> for Variant

source§

fn from(h: Handle) -> Self

Converts to this type from the input type.
source§

impl<K, V> From<HashMap<K, V>> for Variant

source§

fn from(m: HashMap<K, V>) -> Self

Converts to this type from the input type.
source§

impl From<ObjectPath> for Variant

source§

fn from(p: ObjectPath) -> Self

Converts to this type from the input type.
source§

impl<T: StaticVariantType + Into<Variant>> From<Option<T>> for Variant

source§

fn from(v: Option<T>) -> Self

Converts to this type from the input type.
source§

impl From<OsString> for Variant

source§

fn from(s: OsString) -> Self

Converts to this type from the input type.
source§

impl From<PathBuf> for Variant

source§

fn from(p: PathBuf) -> Self

Converts to this type from the input type.
source§

impl From<Signature> for Variant

source§

fn from(s: Signature) -> Self

Converts to this type from the input type.
source§

impl From<String> for Variant

source§

fn from(s: String) -> Self

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

source§

fn from(d: VariantDict) -> Self

Converts to this type from the input type.
source§

impl<T: StaticVariantType + Into<Variant>> From<Vec<T>> for Variant

source§

fn from(v: Vec<T>) -> Self

Converts to this type from the input type.
source§

impl From<bool> for Variant

source§

fn from(v: bool) -> Self

Converts to this type from the input type.
source§

impl From<f64> for Variant

source§

fn from(v: f64) -> Self

Converts to this type from the input type.
source§

impl From<i16> for Variant

source§

fn from(v: i16) -> Self

Converts to this type from the input type.
source§

impl From<i32> for Variant

source§

fn from(v: i32) -> Self

Converts to this type from the input type.
source§

impl From<i64> for Variant

source§

fn from(v: i64) -> Self

Converts to this type from the input type.
source§

impl From<u16> for Variant

source§

fn from(v: u16) -> Self

Converts to this type from the input type.
source§

impl From<u32> for Variant

source§

fn from(v: u32) -> Self

Converts to this type from the input type.
source§

impl From<u64> for Variant

source§

fn from(v: u64) -> Self

Converts to this type from the input type.
source§

impl From<u8> for Variant

source§

fn from(v: u8) -> Self

Converts to this type from the input type.
source§

impl<T: Into<Variant> + StaticVariantType> FromIterator<T> for Variant

source§

fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self

Creates a value from an iterator. Read more
source§

impl FromStr for Variant

§

type Err = Error

The associated error which can be returned from parsing.
source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
source§

impl FromVariant for Variant

source§

fn from_variant(variant: &Variant) -> Option<Self>

Tries to extract a value. Read more
source§

impl HasParamSpec for Variant

§

type ParamSpec = ParamSpecVariant

§

type SetValue = Variant

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

type BuilderFn = fn(_: &'static str, _: &'static VariantTy) -> ParamSpecVariantBuilder<'static>

source§

fn param_spec_builder() -> Self::BuilderFn

source§

impl Hash for Variant

source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl PartialEq for Variant

source§

fn eq(&self, other: &Self) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialOrd for Variant

source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl StaticType for Variant

source§

fn static_type() -> Type

Returns the type identifier of Self.
source§

impl StaticVariantType for Variant

source§

fn static_variant_type() -> Cow<'static, VariantTy>

Returns the VariantType corresponding to Self.
source§

impl ToVariant for Variant

source§

fn to_variant(&self) -> Variant

Returns a Variant clone of self.
source§

impl Eq for Variant

source§

impl Send for Variant

source§

impl Sync for Variant

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where 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 T

source§

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

source§

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

source§

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

source§

impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GPtrArray> for T

source§

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

source§

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

source§

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

source§

impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GSList> for T

source§

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

source§

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

source§

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

source§

impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GList> for T

source§

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

source§

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

source§

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

source§

impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GPtrArray> for T

source§

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

source§

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

source§

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

source§

impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GSList> for T

source§

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

source§

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

source§

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

source§

impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GList> for T

source§

unsafe fn from_glib_none_as_vec(ptr: *const GList) -> Vec<T>

source§

unsafe fn from_glib_container_as_vec(_: *const GList) -> Vec<T>

source§

unsafe fn from_glib_full_as_vec(_: *const GList) -> Vec<T>

source§

impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GPtrArray> for T

source§

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

source§

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

source§

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

source§

impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GSList> for T

source§

unsafe fn from_glib_none_as_vec(ptr: *const GSList) -> Vec<T>

source§

unsafe fn from_glib_container_as_vec(_: *const GSList) -> Vec<T>

source§

unsafe fn from_glib_full_as_vec(_: *const GSList) -> Vec<T>

source§

impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GList> for T

source§

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

source§

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

source§

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

source§

impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GPtrArray> for T

source§

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

source§

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

source§

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

source§

impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GSList> for T

source§

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

source§

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

source§

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

source§

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

source§

impl<T> Property for T
where T: HasParamSpec,

§

type Value = T

source§

impl<T> PropertyGet for T
where T: HasParamSpec,

§

type Value = T

source§

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

source§

impl<T> StaticTypeExt for T
where T: StaticType,

source§

fn ensure_type()

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

impl<T> ToOwned for T
where 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> ToSendValue for T
where T: Send + ToValue + ?Sized,

source§

fn to_send_value(&self) -> SendValue

Returns a SendValue clone of self.
source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T> TransparentType for T

source§

impl<T, U> TryFrom<U> for T
where 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 T
where T: for<'a> FromValue<'a> + StaticType + 'static,

source§

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