Struct zbus::ConnectionBuilder

source ·
pub struct ConnectionBuilder<'a> { /* private fields */ }
Expand description

A builder for zbus::Connection.

Implementations§

source§

impl<'a> ConnectionBuilder<'a>

source

pub fn session() -> Result<Self>

Create a builder for the session/user message bus connection.

source

pub fn system() -> Result<Self>

Create a builder for the system-wide message bus connection.

source

pub fn address<A>(address: A) -> Result<Self>
where A: TryInto<Address>, A::Error: Into<Error>,

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 = ConnectionBuilder::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.

source

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.

source

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.

source

pub fn socket<S: Socket + 'static>(socket: S) -> Self

Create a builder for connection that will use the given socket.

source

pub fn auth_mechanisms(self, auth_mechanisms: &[AuthMechanism]) -> Self

Specify the mechanisms to use during authentication.

source

pub fn cookie_context<C>(self, context: C) -> Result<Self>
where C: Into<Str<'a>>,

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.

source

pub fn cookie_id(self, id: usize) -> Self

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.

source

pub fn p2p(self) -> Self

The to-be-created connection will be a peer-to-peer connection.

source

pub fn server(self, guid: &'a Guid) -> 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.

source

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 = ConnectionBuilder::session()?
    .max_queued(30)
    .build()
    .await?;
assert_eq!(conn.max_queued(), 30);

// Do something useful with `conn`..
source

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.

source

pub fn serve_at<P, I>(self, path: P, iface: I) -> Result<Self>
where I: Interface, P: TryInto<ObjectPath<'a>>, P::Error: Into<Error>,

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.

source

pub fn name<W>(self, well_known_name: W) -> Result<Self>
where W: TryInto<WellKnownName<'a>>, W::Error: Into<Error>,

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 (ConnectionBuilder::build), immediately after interfaces registered (through ConnectionBuilder::serve_at) are advertised. Typically this is exactly what you want.

source

pub fn unique_name<U>(self, unique_name: U) -> Result<Self>
where U: TryInto<UniqueName<'a>>, U::Error: Into<Error>,

Sets the unique name of the connection.

§Panics

This method panics if the to-be-created connection is not a peer-to-peer connection. It will always panic if the connection is to a message bus as it’s the bus that assigns peers their unique names. This is mainly provided for bus implementations. All other users should not need to use this method.

source

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.

Trait Implementations§

source§

impl<'a> Debug for ConnectionBuilder<'a>

source§

fn fmt(&self, __f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> !Freeze for ConnectionBuilder<'a>

§

impl<'a> !RefUnwindSafe for ConnectionBuilder<'a>

§

impl<'a> Send for ConnectionBuilder<'a>

§

impl<'a> Sync for ConnectionBuilder<'a>

§

impl<'a> Unpin for ConnectionBuilder<'a>

§

impl<'a> !UnwindSafe for ConnectionBuilder<'a>

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same for T

source§

type Output = T

Should always be Self
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

source§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more