# Module glib::variant [−] [src]

`Variant` binding and helper traits.

`Variant` is an immutable dynamically-typed generic container. Its type and value are defined at construction and never change.

`Variant` types are described by `VariantType` "type strings".

Although `GVariant` supports arbitrarily complex types, this binding is currently limited to the basic ones: `bool`, `u8`, `i16`, `u16`, `i32`, `u32`, `i64`, `u64`, `f64` and `&str`/`String`.

# Examples

    use glib::prelude::*; // or `use gtk::prelude::*;`
    use glib::Variant;

    // Using the `ToVariant` trait.
    let num = 10.to_variant();

    // `is` tests the type of the value.
    assert!(num.is::<i32>());

    // `get` tries to extract the value.
    assert_eq!(num.get::<i32>(), Some(10));
    assert_eq!(num.get::<u32>(), None);

    // `Variant` implements `From`
    let hello = Variant::from("Hello!");

    // `get_str` tries to borrow a string slice.
    assert_eq!(hello.get_str(), Some("Hello!"));
    assert_eq!(num.get_str(), None);

## Structs

Variant | A generic immutable value capable of carrying various types.

## Traits

FromVariant | Extracts a value.
StaticVariantType | Returns `VariantType` of `Self`.
ToVariant | Converts to `Variant`.

# Help

## Keyboard Shortcuts

?
  Show this help dialog
S
  Focus the search field
↑
  Move up in search results
↓
  Move down in search results
↹
  Switch tab
⏎
  Go to active search result
+ / -
  Collapse/expand all sections

## Search Tricks

Prefix searches with a type followed by a colon (e.g. `fn:`) to restrict the search to a given type.

Accepted types are: `fn`, `mod`, `struct`, `enum`, `trait`, `type`, `macro`, and `const`.

Search functions by type signature (e.g. `vec -> usize` or `* -> vec`)