Skip to main content

Message

Struct Message 

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

Implementations§

Source§

impl Message

Source

pub fn topic(&self) -> &str

Examples found in repository?
examples/pubsub.rs (line 24)
7async fn main() {
8    let test_topic = "test/topic1";
9    // define client configuration
10    let config = Config::new("localhost:2873")
11        .set_timeout(Duration::from_secs(5))
12        .build();
13    // connect PSRT client
14    let mut client = Client::connect(&config).await.expect("Failed to connect");
15    // subscribe to the topic
16    client.subscribe(test_topic.to_owned()).await.unwrap();
17    // get data channel
18    let data_channel = client.take_data_channel().unwrap();
19    let receiver_fut = tokio::spawn(async move {
20        // receive messages from the server
21        while let Ok(message) = data_channel.recv().await {
22            println!(
23                "topic: {}, data: {}",
24                message.topic(),
25                message.data_as_str().unwrap()
26            );
27        }
28    });
29    for _ in 0..3 {
30        // if required, check that the client is still connected
31        assert!(client.is_connected());
32        // publish a message
33        client
34            .publish(
35                DEFAULT_PRIORITY,
36                test_topic.to_owned(),
37                "hello".as_bytes().to_vec(),
38            )
39            .await
40            .unwrap();
41        sleep(Duration::from_secs(1)).await;
42    }
43    client.bye().await.unwrap();
44    receiver_fut.await.unwrap();
45}
Source

pub fn data(&self) -> &[u8]

Source

pub fn data_as_str(&self) -> Result<&str, Utf8Error>

§Errors

Will return Err if data is unable to be parsed as utf8

Examples found in repository?
examples/pubsub.rs (line 25)
7async fn main() {
8    let test_topic = "test/topic1";
9    // define client configuration
10    let config = Config::new("localhost:2873")
11        .set_timeout(Duration::from_secs(5))
12        .build();
13    // connect PSRT client
14    let mut client = Client::connect(&config).await.expect("Failed to connect");
15    // subscribe to the topic
16    client.subscribe(test_topic.to_owned()).await.unwrap();
17    // get data channel
18    let data_channel = client.take_data_channel().unwrap();
19    let receiver_fut = tokio::spawn(async move {
20        // receive messages from the server
21        while let Ok(message) = data_channel.recv().await {
22            println!(
23                "topic: {}, data: {}",
24                message.topic(),
25                message.data_as_str().unwrap()
26            );
27        }
28    });
29    for _ in 0..3 {
30        // if required, check that the client is still connected
31        assert!(client.is_connected());
32        // publish a message
33        client
34            .publish(
35                DEFAULT_PRIORITY,
36                test_topic.to_owned(),
37                "hello".as_bytes().to_vec(),
38            )
39            .await
40            .unwrap();
41        sleep(Duration::from_secs(1)).await;
42    }
43    client.bye().await.unwrap();
44    receiver_fut.await.unwrap();
45}
Source

pub fn from_buf(buf: &mut Vec<u8>, priority: u8) -> Result<Self, Error>

§Errors

Will return Err on buffer parse errors

Trait Implementations§

Source§

impl Clone for Message

Source§

fn clone(&self) -> Message

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Message

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.