pub struct Client {
    pub server: String,
    pub port: u16,
    /* private fields */
}

Fields§

§server: String§port: u16

Implementations§

source§

impl Client

source

pub fn new(server: String, port: u16) -> Client

Examples found in repository?
examples/subscribe.rs (line 10)
8
9
10
11
12
13
14
15
16
17
18
async fn main() -> Result<(), String> {
    // initialize the client.
    let mut client = simple_pub_sub::client::Client::new("localhost".to_string(), 6480);
    // set the callback function.
    client.on_message(on_msg);
    // connect the client.
    let _ = client.connect().await;
    // subscribe to the given topic.
    let _ = client.subscribe("abc".to_string()).await;
    Ok(())
}
More examples
Hide additional examples
examples/publish.rs (line 4)
2
3
4
5
6
7
8
9
10
11
12
13
14
15
async fn main() -> Result<(), String> {
    // initialize the client.
    let mut client = simple_pub_sub::client::Client::new("localhost".to_string(), 6480);
    // connect the client.
    let _ = client.connect().await;
    // subscribe to the given topic.
    let _ = client
        .publish(
            "abc".to_string(),
            "test message".to_string().into_bytes().to_vec(),
        )
        .await;
    Ok(())
}
source

pub fn on_message(&mut self, callback: fn(_: String, _: Vec<u8>))

Examples found in repository?
examples/subscribe.rs (line 12)
8
9
10
11
12
13
14
15
16
17
18
async fn main() -> Result<(), String> {
    // initialize the client.
    let mut client = simple_pub_sub::client::Client::new("localhost".to_string(), 6480);
    // set the callback function.
    client.on_message(on_msg);
    // connect the client.
    let _ = client.connect().await;
    // subscribe to the given topic.
    let _ = client.subscribe("abc".to_string()).await;
    Ok(())
}
source

pub async fn connect(&mut self) -> Result<(), Error>

Examples found in repository?
examples/subscribe.rs (line 14)
8
9
10
11
12
13
14
15
16
17
18
async fn main() -> Result<(), String> {
    // initialize the client.
    let mut client = simple_pub_sub::client::Client::new("localhost".to_string(), 6480);
    // set the callback function.
    client.on_message(on_msg);
    // connect the client.
    let _ = client.connect().await;
    // subscribe to the given topic.
    let _ = client.subscribe("abc".to_string()).await;
    Ok(())
}
More examples
Hide additional examples
examples/publish.rs (line 6)
2
3
4
5
6
7
8
9
10
11
12
13
14
15
async fn main() -> Result<(), String> {
    // initialize the client.
    let mut client = simple_pub_sub::client::Client::new("localhost".to_string(), 6480);
    // connect the client.
    let _ = client.connect().await;
    // subscribe to the given topic.
    let _ = client
        .publish(
            "abc".to_string(),
            "test message".to_string().into_bytes().to_vec(),
        )
        .await;
    Ok(())
}
source

pub async fn post(self, msg: Msg) -> Result<Vec<u8>, Error>

source

pub async fn publish(self, topic: String, message: Vec<u8>) -> Result<(), Error>

Examples found in repository?
examples/publish.rs (lines 9-12)
2
3
4
5
6
7
8
9
10
11
12
13
14
15
async fn main() -> Result<(), String> {
    // initialize the client.
    let mut client = simple_pub_sub::client::Client::new("localhost".to_string(), 6480);
    // connect the client.
    let _ = client.connect().await;
    // subscribe to the given topic.
    let _ = client
        .publish(
            "abc".to_string(),
            "test message".to_string().into_bytes().to_vec(),
        )
        .await;
    Ok(())
}
source

pub async fn query(self, topic: String) -> Result<String, Error>

source

pub async fn subscribe(self, topic: String) -> Result<(), Error>

Examples found in repository?
examples/subscribe.rs (line 16)
8
9
10
11
12
13
14
15
16
17
18
async fn main() -> Result<(), String> {
    // initialize the client.
    let mut client = simple_pub_sub::client::Client::new("localhost".to_string(), 6480);
    // set the callback function.
    client.on_message(on_msg);
    // connect the client.
    let _ = client.connect().await;
    // subscribe to the given topic.
    let _ = client.subscribe("abc".to_string()).await;
    Ok(())
}

Trait Implementations§

source§

impl Debug for Client

source§

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

Formats the value using the given formatter. 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, 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>,

§

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>,

§

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.