zbus/blocking/proxy/
builder.rs
1use static_assertions::assert_impl_all;
2use zbus_names::{BusName, InterfaceName};
3use zvariant::ObjectPath;
4
5use crate::{blocking::Connection, proxy::CacheProperties, utils::block_on, Error, Result};
6
7pub use crate::proxy::ProxyDefault;
8
9#[derive(Debug, Clone)]
11pub struct Builder<'a, T = ()>(crate::proxy::Builder<'a, T>);
12
13assert_impl_all!(Builder<'_>: Send, Sync, Unpin);
14
15impl<'a, T> Builder<'a, T> {
16 pub fn destination<D>(self, destination: D) -> Result<Self>
18 where
19 D: TryInto<BusName<'a>>,
20 D::Error: Into<Error>,
21 {
22 crate::proxy::Builder::destination(self.0, destination).map(Self)
23 }
24
25 pub fn path<P>(self, path: P) -> Result<Self>
27 where
28 P: TryInto<ObjectPath<'a>>,
29 P::Error: Into<Error>,
30 {
31 crate::proxy::Builder::path(self.0, path).map(Self)
32 }
33
34 pub fn interface<I>(self, interface: I) -> Result<Self>
36 where
37 I: TryInto<InterfaceName<'a>>,
38 I::Error: Into<Error>,
39 {
40 crate::proxy::Builder::interface(self.0, interface).map(Self)
41 }
42
43 #[must_use]
45 pub fn cache_properties(self, cache: CacheProperties) -> Self {
46 Self(self.0.cache_properties(cache))
47 }
48
49 #[must_use]
51 pub fn uncached_properties(self, properties: &[&'a str]) -> Self {
52 Self(self.0.uncached_properties(properties))
53 }
54
55 pub fn build(self) -> Result<T>
61 where
62 T: From<crate::Proxy<'a>>,
63 {
64 block_on(self.0.build())
65 }
66}
67
68impl<'a, T> Builder<'a, T>
69where
70 T: ProxyDefault,
71{
72 #[must_use]
74 pub fn new(conn: &Connection) -> Self {
75 Self(crate::proxy::Builder::new(&conn.clone().into()))
76 }
77
78 #[must_use]
80 #[deprecated(
81 since = "4.0.0",
82 note = "use `Builder::new` instead, which is now generic over the proxy type"
83 )]
84 pub fn new_bare(conn: &Connection) -> Self {
85 Self::new(conn)
86 }
87}