Skip to content

Commit 14aba57

Browse files
committed
♻️ zm: Some refactoring of internal interface API
1 parent 1a1177e commit 14aba57

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

zbus_macros/src/iface.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -354,12 +354,7 @@ pub fn expand<T: AttrParse + Into<ImplAttrs>, M: AttrParse + Into<MethodAttrs>>(
354354

355355
let (iface_name, with_spawn, mut proxy) = {
356356
let (name, interface, spawn, proxy) = match T::parse_nested_metas(args)?.into() {
357-
ImplAttrs::New(new) => (
358-
new.name,
359-
new.interface,
360-
new.spawn,
361-
new.proxy.map(|p| Proxy::new(ty, p)),
362-
),
357+
ImplAttrs::New(new) => (new.name, new.interface, new.spawn, new.proxy),
363358
// New proxy attributes are not supported for old `dbus_interface`.
364359
ImplAttrs::Old(old) => (old.name, old.interface, old.spawn, None),
365360
};
@@ -373,6 +368,7 @@ pub fn expand<T: AttrParse + Into<ImplAttrs>, M: AttrParse + Into<MethodAttrs>>(
373368
"`name` and `interface` attributes should not be specified at the same time",
374369
)),
375370
};
371+
let proxy = proxy.map(|p| Proxy::new(ty, &name, p, &zbus));
376372

377373
(name, !spawn.unwrap_or(false), proxy)
378374
};
@@ -773,7 +769,7 @@ pub fn expand<T: AttrParse + Into<ImplAttrs>, M: AttrParse + Into<MethodAttrs>>(
773769
}
774770

775771
if let Some(proxy) = &mut proxy {
776-
proxy.add_method(info, &properties, &zbus);
772+
proxy.add_method(info, &properties);
777773
}
778774
}
779775

@@ -794,7 +790,7 @@ pub fn expand<T: AttrParse + Into<ImplAttrs>, M: AttrParse + Into<MethodAttrs>>(
794790
}
795791
};
796792

797-
let proxy = proxy.map(|proxy| proxy.gen(&iface_name, &zbus));
793+
let proxy = proxy.map(|proxy| proxy.gen());
798794

799795
Ok(quote! {
800796
#input
@@ -1307,6 +1303,10 @@ impl Parse for ImplItemSignal {
13071303
struct Proxy {
13081304
// The type name
13091305
ty: Ident,
1306+
// The interface name
1307+
iface_name: String,
1308+
// The zbus crate
1309+
zbus: TokenStream,
13101310

13111311
// Input
13121312
attrs: ProxyAttributes,
@@ -1316,20 +1316,17 @@ struct Proxy {
13161316
}
13171317

13181318
impl Proxy {
1319-
fn new(ty: &Ident, attrs: ProxyAttributes) -> Self {
1319+
fn new(ty: &Ident, iface_name: &str, attrs: ProxyAttributes, zbus: &TokenStream) -> Self {
13201320
Self {
1321+
iface_name: iface_name.to_string(),
13211322
ty: ty.clone(),
1323+
zbus: zbus.clone(),
13221324
attrs,
13231325
methods: quote!(),
13241326
}
13251327
}
13261328

1327-
fn add_method(
1328-
&mut self,
1329-
method_info: MethodInfo,
1330-
properties: &BTreeMap<String, Property<'_>>,
1331-
zbus: &TokenStream,
1332-
) {
1329+
fn add_method(&mut self, method_info: MethodInfo, properties: &BTreeMap<String, Property<'_>>) {
13331330
let inputs: Punctuated<PatType, Comma> = method_info
13341331
.typed_inputs
13351332
.iter()
@@ -1386,14 +1383,15 @@ impl Proxy {
13861383
}
13871384
}
13881385
let cfg_attrs = method_info.cfg_attrs;
1386+
let zbus = &self.zbus;
13891387
self.methods.extend(quote! {
13901388
#(#cfg_attrs)*
13911389
#[zbus(#proxy_method_attrs)]
13921390
fn #ident(&self, #inputs) -> #zbus::Result<#ret>;
13931391
});
13941392
}
13951393

1396-
fn gen(&self, iface_name: &str, zbus: &TokenStream) -> TokenStream {
1394+
fn gen(&self) -> TokenStream {
13971395
let attrs = &self.attrs;
13981396
let (
13991397
assume_defaults,
@@ -1432,6 +1430,8 @@ impl Proxy {
14321430
&self.ty,
14331431
&self.methods,
14341432
);
1433+
let iface_name = &self.iface_name;
1434+
let zbus = &self.zbus;
14351435
quote! {
14361436
#[#zbus::proxy(
14371437
name = #iface_name,

0 commit comments

Comments
 (0)