Client

Struct Client 

Source
pub struct Client { /* private fields */ }

Implementations§

Source§

impl Client

Source

pub async fn connect(config: &Config) -> Result<Self, Error>

Examples found in repository?
examples/client_listener.rs (line 11)
7async fn main() -> Result<(), Box<dyn std::error::Error>> {
8    let name = "test.client.listener";
9    // create a new client instance
10    let config = Config::new("/tmp/busrt.sock", name);
11    let mut client = Client::connect(&config).await?;
12    // subscribe to all topics
13    let opc = client.subscribe("#", QoS::Processed).await?.expect("no op");
14    opc.await??;
15    // handle incoming frames
16    let rx = client.take_event_channel().unwrap();
17    while let Ok(frame) = rx.recv().await {
18        println!(
19            "Frame from {}: {:?} {:?} {}",
20            frame.sender(),
21            frame.kind(),
22            frame.topic(),
23            std::str::from_utf8(frame.payload()).unwrap_or("something unreadable")
24        );
25    }
26    Ok(())
27}
More examples
Hide additional examples
examples/client_sender.rs (line 11)
7async fn main() -> Result<(), Box<dyn std::error::Error>> {
8    let name = "test.client.sender";
9    // create a new client instance
10    let config = Config::new("/tmp/busrt.sock", name);
11    let mut client = Client::connect(&config).await?;
12    // publish to a topic
13    let opc = client
14        .publish("some/topic", "hello".as_bytes().into(), QoS::Processed)
15        .await?
16        .expect("no op");
17    opc.await??;
18    // send a direct message
19    let opc = client
20        .send(
21            "test.client.listener",
22            "hello".as_bytes().into(),
23            QoS::Processed,
24        )
25        .await?
26        .expect("no op");
27    opc.await??;
28    // send a broadcast message
29    let opc = client
30        .send_broadcast("test.*", "hello everyone".as_bytes().into(), QoS::Processed)
31        .await?
32        .expect("no op");
33    opc.await??;
34    Ok(())
35}
Source

pub async fn connect_stream( stream: UnixStream, config: &Config, ) -> Result<Self, Error>

Source

pub async fn register_secondary(&self) -> Result<Self, Error>

Source

pub fn get_timeout(&self) -> Duration

Trait Implementations§

Source§

impl AsyncClient for Client

Source§

fn take_event_channel(&mut self) -> Option<EventChannel>

Source§

fn get_connected_beacon(&self) -> Option<Arc<AtomicBool>>

Source§

fn send<'life0, 'life1, 'async_trait>( &'life0 mut self, target: &'life1 str, payload: Cow<'async_trait>, qos: QoS, ) -> Pin<Box<dyn Future<Output = Result<OpConfirm, Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Source§

fn zc_send<'life0, 'life1, 'async_trait>( &'life0 mut self, target: &'life1 str, header: Cow<'async_trait>, payload: Cow<'async_trait>, qos: QoS, ) -> Pin<Box<dyn Future<Output = Result<OpConfirm, Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Source§

fn send_broadcast<'life0, 'life1, 'async_trait>( &'life0 mut self, target: &'life1 str, payload: Cow<'async_trait>, qos: QoS, ) -> Pin<Box<dyn Future<Output = Result<OpConfirm, Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Source§

fn publish<'life0, 'life1, 'async_trait>( &'life0 mut self, target: &'life1 str, payload: Cow<'async_trait>, qos: QoS, ) -> Pin<Box<dyn Future<Output = Result<OpConfirm, Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Source§

fn publish_for<'life0, 'life1, 'life2, 'async_trait>( &'life0 mut self, target: &'life1 str, receiver: &'life2 str, payload: Cow<'async_trait>, qos: QoS, ) -> Pin<Box<dyn Future<Output = Result<OpConfirm, Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Source§

fn subscribe<'life0, 'life1, 'async_trait>( &'life0 mut self, topic: &'life1 str, qos: QoS, ) -> Pin<Box<dyn Future<Output = Result<OpConfirm, Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Source§

fn unsubscribe<'life0, 'life1, 'async_trait>( &'life0 mut self, topic: &'life1 str, qos: QoS, ) -> Pin<Box<dyn Future<Output = Result<OpConfirm, Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Source§

fn subscribe_bulk<'life0, 'life1, 'life2, 'async_trait>( &'life0 mut self, topics: &'life1 [&'life2 str], qos: QoS, ) -> Pin<Box<dyn Future<Output = Result<OpConfirm, Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Source§

fn unsubscribe_bulk<'life0, 'life1, 'life2, 'async_trait>( &'life0 mut self, topics: &'life1 [&'life2 str], qos: QoS, ) -> Pin<Box<dyn Future<Output = Result<OpConfirm, Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Source§

fn exclude<'life0, 'life1, 'async_trait>( &'life0 mut self, topic: &'life1 str, qos: QoS, ) -> Pin<Box<dyn Future<Output = Result<OpConfirm, Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

exclude a topic. it is highly recommended to exclude topics first, then call subscribe operations to avoid receiving unwanted messages. excluding topics is also an additional heavy operation so use it only when there is no other way.
Source§

fn unexclude<'life0, 'life1, 'async_trait>( &'life0 mut self, topic: &'life1 str, qos: QoS, ) -> Pin<Box<dyn Future<Output = Result<OpConfirm, Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

unexclude a topic (include back but not subscribe)
Source§

fn exclude_bulk<'life0, 'life1, 'life2, 'async_trait>( &'life0 mut self, topics: &'life1 [&'life2 str], qos: QoS, ) -> Pin<Box<dyn Future<Output = Result<OpConfirm, Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

exclude multiple topics
Source§

fn unexclude_bulk<'life0, 'life1, 'life2, 'async_trait>( &'life0 mut self, topics: &'life1 [&'life2 str], qos: QoS, ) -> Pin<Box<dyn Future<Output = Result<OpConfirm, Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

unexclude multiple topics (include back but not subscribe)
Source§

fn ping<'life0, 'async_trait>( &'life0 mut self, ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source§

fn is_connected(&self) -> bool

Source§

fn get_timeout(&self) -> Option<Duration>

Source§

fn get_name(&self) -> &str

Source§

impl Drop for Client

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl !Freeze for Client

§

impl !RefUnwindSafe for Client

§

impl Send for Client

§

impl Sync for Client

§

impl Unpin for Client

§

impl !UnwindSafe for Client

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