#[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 the type of the value.

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

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

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

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.

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.

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 children with the specified type.

Panics

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

Creates a new Variant array from a fixed array.

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.

Creates a new maybe Variant.

Creates a new maybe Variant from a child.

Creates a new maybe Variant with Nothing.

Extract the value of a maybe Variant.

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

Panics

Panics if compiled with debug_assertions and the variant is not maybe-typed.

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

A variant can be recreated from this output via Variant::parse.

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

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.

Returns the size of 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.

Returns a copy of the variant in the opposite endianness.

Determines the number of children in a container GVariant instance.

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

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

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Formats the value using the given formatter. Read more

Converts to this type from the input type.

Creates a value from an iterator. Read more

The associated error which can be returned from parsing.

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

Tries to extract a value. Read more

Feeds this value into the given Hasher. Read more

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

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

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

This method tests greater than or equal to (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

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

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

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

Returns a SendValue clone of self.

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.