Skip to content

Commit 3b783df

Browse files
committed
Use Borrow, add double f64 test
1 parent acd9fd1 commit 3b783df

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

glib-macros/src/properties.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -498,10 +498,10 @@ fn expand_getset_properties_impl(props: &[PropDesc]) -> TokenStream2 {
498498
quote!(#fn_prototype { #body })
499499
});
500500
let setter = (p.set.is_some() && !p.flags.contains(&"construct_only")).then(|| {
501-
let body = quote!(self.set_property_from_value(#name, &value.as_ref().to_value()));
501+
let body = quote!(self.set_property_from_value(#name, &std::borrow::Borrow::borrow(&value).to_value()));
502502
let fn_prototype = {
503503
let ident = format_ident!("set_{}", ident);
504-
quote!(pub fn #ident<'a>(&self, value: impl AsRef<<<#ty as #crate_ident::Property>::Value as #crate_ident::HasParamSpec>::SetValue>))
504+
quote!(pub fn #ident<'a>(&self, value: impl std::borrow::Borrow<<<#ty as #crate_ident::Property>::Value as #crate_ident::HasParamSpec>::SetValue>))
505505
};
506506
quote!(#fn_prototype { #body })
507507
});

glib-macros/tests/properties.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ fn props() {
4848
pub struct Foo {
4949
#[property(get, set)]
5050
bar: Mutex<String>,
51+
#[property(get, set)]
52+
double: RefCell<f64>,
5153
// The following property doesn't store any data. The value of the property is calculated
5254
// when the value is accessed.
5355
#[property(get = Self::hello_world)]
@@ -233,6 +235,9 @@ fn props() {
233235
"setter working".to_string()
234236
);
235237

238+
myfoo.set_double(0.1);
239+
assert_eq!(myfoo.property::<f64>("double"), 0.1);
240+
236241
// simple with various String types
237242
myfoo.set_bar(String::from("setter working"));
238243
myfoo.set_bar(glib::GString::from("setter working"));

0 commit comments

Comments
 (0)