Skip to content

Commit 1737eed

Browse files
committed
Refactor, remove unneeded code
1 parent aa75d96 commit 1737eed

File tree

1 file changed

+23
-22
lines changed

1 file changed

+23
-22
lines changed

glib-macros/src/properties.rs

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,12 @@ fn expand_property_fn(props: &[PropDesc]) -> TokenStream2 {
386386
})
387387
});
388388
quote!(
389-
fn derived_property<'a>(&self, _obj: &Self::Type, id: usize, pspec: &'a #crate_ident::ParamSpec) -> Result<#crate_ident::Value, #crate_ident::subclass::object::MissingPropertyHandler<'a>> {
389+
fn derived_property<'a>(
390+
&self,
391+
_obj: &Self::Type,
392+
id: usize,
393+
pspec: &'a #crate_ident::ParamSpec
394+
) -> Result<#crate_ident::Value, #crate_ident::subclass::object::MissingPropertyHandler<'a>> {
390395
let prop = DerivedPropertiesEnum::try_from(id-1)
391396
.map_err(|_| #crate_ident::subclass::object::MissingPropertyHandler::<'a>::from(pspec))?;
392397
match prop {
@@ -442,7 +447,12 @@ fn expand_set_property_fn(props: &[PropDesc]) -> TokenStream2 {
442447
})
443448
});
444449
quote!(
445-
fn derived_set_property<'a>(&self, _obj: &Self::Type, id: usize, value: &#crate_ident::Value, pspec: &'a #crate_ident::ParamSpec) -> Result<(), #crate_ident::subclass::object::MissingPropertyHandler<'a>> {
450+
fn derived_set_property<'a>(&self,
451+
_obj: &Self::Type,
452+
id: usize,
453+
value: &#crate_ident::Value,
454+
pspec: &'a #crate_ident::ParamSpec
455+
) -> Result<(), #crate_ident::subclass::object::MissingPropertyHandler<'a>> {
446456
let prop = DerivedPropertiesEnum::try_from(id-1)
447457
.map_err(|_| #crate_ident::subclass::object::MissingPropertyHandler::<'a>::from(pspec))?;
448458
match prop {
@@ -492,18 +502,15 @@ fn expand_getset_properties_impl(props: &[PropDesc]) -> TokenStream2 {
492502
let ty = &p.ty;
493503

494504
let getter = p.get.is_some().then(|| {
495-
let body = quote!(self.property::<<#ty as #crate_ident::Property>::Value>(#name));
496-
let fn_prototype =
497-
{ quote!(pub fn #ident(&self) -> <#ty as #crate_ident::Property>::Value) };
498-
quote!(#fn_prototype { #body })
505+
quote!(pub fn #ident(&self) -> <#ty as #crate_ident::Property>::Value {
506+
self.property::<<#ty as #crate_ident::Property>::Value>(#name)
507+
})
499508
});
500509
let setter = (p.set.is_some() && !p.flags.contains(&"construct_only")).then(|| {
501-
let body = quote!(self.set_property_from_value(#name, &std::borrow::Borrow::borrow(&value).to_value()));
502-
let fn_prototype = {
503-
let ident = format_ident!("set_{}", ident);
504-
quote!(pub fn #ident<'a>(&self, value: impl std::borrow::Borrow<<<#ty as #crate_ident::Property>::Value as #crate_ident::HasParamSpec>::SetValue>))
505-
};
506-
quote!(#fn_prototype { #body })
510+
let ident = format_ident!("set_{}", ident);
511+
quote!(pub fn #ident<'a>(&self, value: impl std::borrow::Borrow<<<#ty as #crate_ident::Property>::Value as #crate_ident::HasParamSpec>::SetValue>) {
512+
self.set_property_from_value(#name, &std::borrow::Borrow::borrow(&value).to_value())
513+
})
507514
});
508515
let span = p.attrs_span;
509516
quote_spanned!(span=>
@@ -518,12 +525,9 @@ fn expand_connect_prop_notify_impl(props: &[PropDesc]) -> TokenStream2 {
518525
let crate_ident = crate_ident_new();
519526
let connection_fns = props.iter().map(|p| {
520527
let name = &p.name;
521-
let fn_prototype = {
522-
let fn_ident = format_ident!("connect_{}_notify", name_to_ident(name));
523-
quote!(pub fn #fn_ident<F: Fn(&Self) + 'static>(&self, f: F) -> #crate_ident::SignalHandlerId)
524-
};
528+
let fn_ident = format_ident!("connect_{}_notify", name_to_ident(name));
525529
let span = p.attrs_span;
526-
quote_spanned!(span=> #fn_prototype {
530+
quote_spanned!(span=> pub fn #fn_ident<F: Fn(&Self) + 'static>(&self, f: F) -> #crate_ident::SignalHandlerId {
527531
self.connect_notify_local(Some(#name), move |this, _| {
528532
f(this)
529533
})
@@ -536,13 +540,10 @@ fn expand_emit_impl(props: &[PropDesc]) -> TokenStream2 {
536540
let crate_ident = crate_ident_new();
537541
let emit_fns = props.iter().map(|p| {
538542
let name = &p.name;
539-
let fn_prototype = {
540-
let fn_ident = format_ident!("emit_{}", name_to_ident(name));
541-
quote!(pub fn #fn_ident(&self))
542-
};
543+
let fn_ident = format_ident!("emit_{}", name_to_ident(name));
543544
let span = p.attrs_span;
544545
let enum_ident = name_to_enum_ident(name.value());
545-
quote_spanned!(span=> #fn_prototype {
546+
quote_spanned!(span=> pub fn #fn_ident(&self) {
546547
self.notify_by_pspec(
547548
&<<Self as #crate_ident::object::ObjectSubclassIs>::Subclass
548549
as #crate_ident::subclass::object::DerivedObjectProperties>::derived_properties()

0 commit comments

Comments
 (0)