Struct glib::variant::Variant[][src]

pub struct Variant(_);
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.

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 &[u8] from a variant of type ay (array of bytes).

Returns an error if the type is not ay.

Creates a new GVariant array from children.

All children must be of type T.

Creates a new GVariant tuple from children.

Creates a new maybe Variant.

Constructs a new serialised-mode GVariant instance.

Constructs a new serialised-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.

Returns the serialised form of a GVariant instance.

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

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

Performs the conversion.

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

Performs the conversion.

Performs the conversion.

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)

recently added

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.