pub struct Config { /* private fields */ }Implementations§
Source§impl Config
impl Config
Sourcepub fn new(path: &str, name: &str) -> Self
pub fn new(path: &str, name: &str) -> Self
path - /path/to/socket (must end with .sock .socket or .ipc) or host:port for websockets use ws://host[:port] or wss://host[:port]
name - an unique client name
Examples found in repository?
examples/client_listener.rs (line 10)
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 10)
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 fn buf_size(self, size: usize) -> Self
pub fn buf_ttl(self, ttl: Duration) -> Self
pub fn queue_size(self, size: usize) -> Self
pub fn timeout(self, timeout: Duration) -> Self
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Config
impl RefUnwindSafe for Config
impl Send for Config
impl Sync for Config
impl Unpin for Config
impl UnsafeUnpin for Config
impl UnwindSafe for Config
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