pub struct Client { /* private fields */ }Implementations§
Source§impl Client
impl Client
Sourcepub async fn connect(config: &Config) -> Result<Self, Error>
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
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}pub async fn connect_stream( stream: UnixStream, config: &Config, ) -> Result<Self, Error>
pub async fn register_secondary(&self) -> Result<Self, Error>
pub fn get_timeout(&self) -> Duration
Trait Implementations§
Source§impl AsyncClient for Client
impl AsyncClient for Client
fn take_event_channel(&mut self) -> Option<EventChannel>
fn get_connected_beacon(&self) -> Option<Arc<AtomicBool>>
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,
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,
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,
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,
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,
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,
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,
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,
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,
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,
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,
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,
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)
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,
fn is_connected(&self) -> bool
fn get_timeout(&self) -> Option<Duration>
fn get_name(&self) -> &str
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more