Struct zbus::connection::Builder
source · pub struct Builder<'a> { /* private fields */ }
Expand description
A builder for zbus::Connection
.
Implementations§
source§impl<'a> Builder<'a>
impl<'a> Builder<'a>
sourcepub fn address<A>(address: A) -> Result<Self>
pub fn address<A>(address: A) -> Result<Self>
Create a builder for connection that will use the given D-Bus bus address.
§Example
Here is an example of connecting to an IBus service:
let addr = "unix:\
path=/home/zeenix/.cache/ibus/dbus-ET0Xzrk9,\
guid=fdd08e811a6c7ebe1fef0d9e647230da";
let conn = Builder::address(addr)?
.build()
.await?;
// Do something useful with `conn`..
Note: The IBus address is different for each session. You can find the address for your
current session using ibus address
command.
sourcepub fn unix_stream(stream: UnixStream) -> Self
pub fn unix_stream(stream: UnixStream) -> Self
Create a builder for connection that will use the given unix stream.
If the default async-io
feature is disabled, this method will expect
tokio::net::UnixStream
argument.
Since tokio currently does not support Unix domain sockets on Windows, this method
is not available when the tokio
feature is enabled and building for Windows target.
sourcepub fn tcp_stream(stream: TcpStream) -> Self
pub fn tcp_stream(stream: TcpStream) -> Self
Create a builder for connection that will use the given TCP stream.
If the default async-io
feature is disabled, this method will expect
tokio::net::TcpStream
argument.
sourcepub fn vsock_stream(stream: VsockStream) -> Self
pub fn vsock_stream(stream: VsockStream) -> Self
Create a builder for connection that will use the given VSOCK stream.
This method is only available when either vsock
or tokio-vsock
feature is enabled. The
type of stream
is vsock::VsockStream
with vsock
feature and tokio_vsock::VsockStream
with tokio-vsock
feature.
sourcepub fn socket<S: Into<BoxedSplit>>(socket: S) -> Self
pub fn socket<S: Into<BoxedSplit>>(socket: S) -> Self
Create a builder for connection that will use the given socket.
sourcepub fn auth_mechanisms(self, auth_mechanisms: &[AuthMechanism]) -> Self
pub fn auth_mechanisms(self, auth_mechanisms: &[AuthMechanism]) -> Self
Specify the mechanisms to use during authentication.
The cookie context to use during authentication.
This is only used when the cookie
authentication mechanism is enabled and only valid for
server connection.
If not specified, the default cookie context of org_freedesktop_general
will be used.
§Errors
If the given string is not a valid cookie context.
The ID of the cookie to use during authentication.
This is only used when the cookie
authentication mechanism is enabled and only valid for
server connection.
If not specified, the first cookie found in the cookie context file will be used.
sourcepub fn p2p(self) -> Self
pub fn p2p(self) -> Self
The to-be-created connection will be a peer-to-peer connection.
This method is only available when the p2p
feature is enabled.
sourcepub fn server<G>(self, guid: G) -> Result<Self>
pub fn server<G>(self, guid: G) -> Result<Self>
The to-be-created connection will be a server using the given GUID.
The to-be-created connection will wait for incoming client authentication handshake and negotiation messages, for peer-to-peer communications after successful creation.
This method is only available when the p2p
feature is enabled.
sourcepub fn max_queued(self, max: usize) -> Self
pub fn max_queued(self, max: usize) -> Self
Set the capacity of the main (unfiltered) queue.
Since typically you’d want to set this at instantiation time, you can set it through the builder.
§Example
let conn = Builder::session()?
.max_queued(30)
.build()
.await?;
assert_eq!(conn.max_queued(), 30);
// Do something useful with `conn`..
sourcepub fn internal_executor(self, enabled: bool) -> Self
pub fn internal_executor(self, enabled: bool) -> Self
Enable or disable the internal executor thread.
The thread is enabled by default.
See Connection::executor for more details.
sourcepub fn serve_at<P, I>(self, path: P, iface: I) -> Result<Self>
pub fn serve_at<P, I>(self, path: P, iface: I) -> Result<Self>
Register a D-Bus Interface
to be served at a given path.
This is similar to zbus::ObjectServer::at
, except that it allows you to have your
interfaces available immediately after the connection is established. Typically, this is
exactly what you’d want. Also in contrast to zbus::ObjectServer::at
, this method will
replace any previously added interface with the same name at the same path.
sourcepub fn name<W>(self, well_known_name: W) -> Result<Self>
pub fn name<W>(self, well_known_name: W) -> Result<Self>
Register a well-known name for this connection on the bus.
This is similar to zbus::Connection::request_name
, except the name is requested as part
of the connection setup (Builder::build
), immediately after interfaces
registered (through Builder::serve_at
) are advertised. Typically this is
exactly what you want.
sourcepub fn unique_name<U>(self, unique_name: U) -> Result<Self>
pub fn unique_name<U>(self, unique_name: U) -> Result<Self>
Sets the unique name of the connection.
This is mainly provided for bus implementations. All other users should not need to use this
method. Hence why this method is only available when the bus-impl
feature is enabled.
§Panics
It will panic if the connection is to a message bus as it’s the bus that assigns peers their unique names.
sourcepub async fn build(self) -> Result<Connection>
pub async fn build(self) -> Result<Connection>
Build the connection, consuming the builder.
§Errors
Until server-side bus connection is supported, attempting to build such a connection will
result in Error::Unsupported
error.