Skip to content

Commit 3841f31

Browse files
authored
Merge pull request #995 from pbor/strv-pspec
properties: impl HasParamSpec for Vec<String> and StrV
2 parents 9839ec6 + a651ad2 commit 3841f31

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

glib-macros/tests/properties.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ mod foo {
9999
bar: Mutex<String>,
100100
#[property(get, set)]
101101
double: RefCell<f64>,
102+
#[property(get, set)]
103+
string_vec: RefCell<Vec<String>>,
102104
#[property(get = |_| 42.0, set)]
103105
infer_inline_type: RefCell<f64>,
104106
// The following property doesn't store any data. The value of the property is calculated
@@ -197,14 +199,22 @@ mod foo {
197199
fn props() {
198200
let myfoo: foo::Foo = glib::object::Object::new();
199201

200-
// Read bar
202+
// Read values
201203
let bar: String = myfoo.property("bar");
202204
assert_eq!(bar, "".to_string());
205+
let string_vec: Vec<String> = myfoo.property("string-vec");
206+
assert!(string_vec.is_empty());
203207

204-
// Set bar
208+
// Set values
205209
myfoo.set_property("bar", "epic".to_value());
206210
let bar: String = myfoo.property("bar");
207211
assert_eq!(bar, "epic".to_string());
212+
myfoo.set_property("string-vec", ["epic", "more epic"].to_value());
213+
let string_vec: Vec<String> = myfoo.property("string-vec");
214+
assert_eq!(
215+
string_vec,
216+
vec!["epic".to_string(), "more epic".to_string()]
217+
);
208218

209219
// Custom getter
210220
let buzz: String = myfoo.property("buzz");

glib/src/param_spec.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2115,6 +2115,24 @@ impl HasParamSpec for String {
21152115
Self::ParamSpec::builder
21162116
}
21172117
}
2118+
impl HasParamSpec for crate::StrV {
2119+
type ParamSpec = ParamSpecBoxed;
2120+
type SetValue = Self;
2121+
type BuilderFn = fn(&str) -> ParamSpecBoxedBuilder<Self>;
2122+
2123+
fn param_spec_builder() -> Self::BuilderFn {
2124+
Self::ParamSpec::builder
2125+
}
2126+
}
2127+
impl HasParamSpec for Vec<String> {
2128+
type ParamSpec = ParamSpecBoxed;
2129+
type SetValue = Self;
2130+
type BuilderFn = fn(&str) -> ParamSpecBoxedBuilder<Self>;
2131+
2132+
fn param_spec_builder() -> Self::BuilderFn {
2133+
Self::ParamSpec::builder
2134+
}
2135+
}
21182136
impl HasParamSpec for char {
21192137
type ParamSpec = ParamSpecUnichar;
21202138
type SetValue = Self;

0 commit comments

Comments
 (0)