Skip to content

Commit e73ff61

Browse files
authored
Merge pull request #967 from ranfdev/props_clean
impl PropertyGet for T: `HasParamSpec`
2 parents 29b04d5 + 4f6ef8e commit e73ff61

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

glib-macros/tests/properties.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ mod foo {
117117
get = |t: &Self| t.author.borrow().name.to_owned(),
118118
set = Self::set_author_name)]
119119
fake_field: PhantomData<String>,
120+
#[property(get)]
121+
read_only_text: String,
120122
#[property(get, set, explicit_notify, lax_validation)]
121123
custom_flags: RefCell<String>,
122124
#[property(get, set, default = "hello")]
@@ -218,6 +220,12 @@ fn props() {
218220
let author_name: String = myfoo.property("author-nick");
219221
assert_eq!(author_name, "freddy-nick".to_string());
220222

223+
// read_only
224+
assert_eq!(
225+
myfoo.find_property("read_only_text").unwrap().flags(),
226+
ParamFlags::READABLE
227+
);
228+
221229
// custom flags
222230
assert_eq!(
223231
myfoo.find_property("custom_flags").unwrap().flags(),

glib/src/property.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,13 @@ impl<T: PropertySetNested> PropertySet for T {
8080
}
8181
}
8282

83+
impl<T: HasParamSpec> PropertyGet for T {
84+
type Value = T;
85+
fn get<R, F: Fn(&Self::Value) -> R>(&self, f: F) -> R {
86+
f(self)
87+
}
88+
}
89+
8390
impl<T: Copy> PropertyGet for Cell<T> {
8491
type Value = T;
8592
fn get<R, F: Fn(&Self::Value) -> R>(&self, f: F) -> R {

0 commit comments

Comments
 (0)