Struct Builder

Source
pub struct Builder<'a> { /* private fields */ }
Expand description

A builder for zbus::Connection.

The builder allows setting the flags RequestNameFlags::AllowReplacement and RequestNameFlags::ReplaceExisting when requesting names, but the flag RequestNameFlags::DoNotQueue will always be enabled. The reasons are:

  1. There is no indication given to the caller of Self::build that the name(s) request was enqueued and that the requested name might not be available right after building.

  2. The name may be acquired in between the time the name is requested and the crate::fdo::NameAcquiredStream is constructed. As a result the service can miss the crate::fdo::NameAcquired signal.

Implementations§

Source§

impl<'a> Builder<'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 a 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.

Source

pub fn unix_stream(stream: UnixStream) -> Self

Create a builder for a connection that will use the given unix stream.

If the default async-io feature is disabled, this method will expect a 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.

Source

pub fn tcp_stream(stream: TcpStream) -> Self

Create a builder for a connection that will use the given TCP stream.

If the default async-io feature is disabled, this method will expect a tokio::net::TcpStream argument.

Source

pub fn socket<S: Into<BoxedSplit>>(socket: S) -> Self

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

Source

pub fn authenticated_socket<S, G>(socket: S, guid: G) -> Result<Self>
where S: Into<BoxedSplit>, G: TryInto<Guid<'a>>, G::Error: Into<Error>,

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

This is similar to Builder::socket, except that the socket is either already authenticated or does not require authentication.

Source

pub fn auth_mechanism(self, auth_mechanism: AuthMechanism) -> Self

Specify the mechanism to use during authentication.

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

Standard interfaces (Peer, Introspectable, Properties) are added on your behalf. If you attempt to add yours, Builder::build() will fail.

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

The methods Builder::allow_name_replacements and Builder::replace_existing_names allow to set the zbus::fdo::RequestNameFlags used to request the name.

Source

pub fn allow_name_replacements(self, allow_replacement: bool) -> Self

Whether the zbus::fdo::RequestNameFlags::AllowReplacement flag will be set when requesting names.

Source

pub fn replace_existing_names(self, replace_existing: bool) -> Self

Whether the zbus::fdo::RequestNameFlags::ReplaceExisting flag will be set when requesting names.

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 a Error::Unsupported error.

Trait Implementations§

Source§

impl<'a> Debug for Builder<'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 Builder<'a>

§

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

§

impl<'a> Send for Builder<'a>

§

impl<'a> Sync for Builder<'a>

§

impl<'a> Unpin for Builder<'a>

§

impl<'a> !UnwindSafe for Builder<'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, 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<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