Derive Macro glib_macros::Variant
source · #[derive(Variant)]
Expand description
Derive macro for serializing/deserializing custom structs as glib::Variant
s.
Example
use glib::prelude::*;
#[derive(Debug, PartialEq, Eq, glib::Variant)]
struct Foo {
some_string: String,
some_int: i32,
}
let v = Foo { some_string: String::from("bar"), some_int: 1 };
let var = v.to_variant();
assert_eq!(var.get::<Foo>(), Some(v));
When storing Vec
s of fixed size types it is a good idea to wrap these in
glib::FixedSizeVariantArray
as serialization/deserialization will be more efficient.
Example
use glib::prelude::*;
#[derive(Debug, PartialEq, Eq, glib::Variant)]
struct Foo {
some_vec: glib::FixedSizeVariantArray<Vec<u32>, u32>,
some_int: i32,
}
let v = Foo { some_vec: vec![1u32, 2u32].into(), some_int: 1 };
let var = v.to_variant();
assert_eq!(var.get::<Foo>(), Some(v));