Skip to content

Commit f0ece8d

Browse files
committed
impl HasParamSpec on glib::Variant
1 parent 7612a98 commit f0ece8d

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

glib-macros/tests/properties.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ mod foo {
101101
double: RefCell<f64>,
102102
#[property(get, set)]
103103
string_vec: RefCell<Vec<String>>,
104+
#[property(get, set, builder(glib::VariantTy::DOUBLE))]
105+
variant: RefCell<Option<glib::Variant>>,
104106
#[property(get = |_| 42.0, set)]
105107
infer_inline_type: RefCell<f64>,
106108
// The following property doesn't store any data. The value of the property is calculated
@@ -204,6 +206,8 @@ fn props() {
204206
assert_eq!(bar, "".to_string());
205207
let string_vec: Vec<String> = myfoo.property("string-vec");
206208
assert!(string_vec.is_empty());
209+
let var: Option<glib::Variant> = myfoo.property("variant");
210+
assert!(var.is_none());
207211

208212
// Set values
209213
myfoo.set_property("bar", "epic".to_value());
@@ -215,6 +219,10 @@ fn props() {
215219
string_vec,
216220
vec!["epic".to_string(), "more epic".to_string()]
217221
);
222+
let myv = Some(2.0f64.to_variant());
223+
myfoo.set_property("variant", &myv);
224+
let var: Option<glib::Variant> = myfoo.property("variant");
225+
assert_eq!(var, myv);
218226

219227
// Custom getter
220228
let buzz: String = myfoo.property("buzz");

glib/src/param_spec.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2224,6 +2224,17 @@ impl HasParamSpec for bool {
22242224
}
22252225
}
22262226

2227+
impl HasParamSpec for crate::Variant {
2228+
type ParamSpec = ParamSpecVariant;
2229+
type SetValue = Self;
2230+
type BuilderFn =
2231+
fn(&'static str, ty: &'static crate::VariantTy) -> ParamSpecVariantBuilder<'static>;
2232+
2233+
fn param_spec_builder() -> Self::BuilderFn {
2234+
Self::ParamSpec::builder
2235+
}
2236+
}
2237+
22272238
#[cfg(test)]
22282239
mod tests {
22292240
use super::*;

0 commit comments

Comments
 (0)