Struct simple_pub_sub::client::Client
source · pub struct Client {
pub client_type: PubSubClient,
/* private fields */
}Expand description
Simple pub sub Client
Fields§
§client_type: PubSubClientImplementations§
source§impl Client
impl Client
sourcepub fn new(client_type: PubSubClient) -> Client
pub fn new(client_type: PubSubClient) -> Client
Creates a new instance of Client
Examples found in repository?
examples/subscribe_unix.rs (lines 11-13)
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
async fn main() -> Result<(), String> {
let client_type = simple_pub_sub::client::PubSubUnixClient {
path: "/tmp/simple.sock".to_string(),
};
// initialize the client.
let mut client = simple_pub_sub::client::Client::new(
simple_pub_sub::client::PubSubClient::Unix(client_type),
);
// 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
examples/subscribe_tcp.rs (line 13)
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
async fn main() -> Result<(), String> {
let client_type = simple_pub_sub::client::PubSubTcpClient {
server: "localhost".to_string(),
port: 6480,
};
// initialize the client.
let mut client =
simple_pub_sub::client::Client::new(simple_pub_sub::client::PubSubClient::Tcp(client_type));
// 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(())
}examples/publish_unix.rs (lines 7-9)
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
async fn main() -> Result<(), String> {
let client_type = simple_pub_sub::client::PubSubUnixClient {
path: "/tmp/simple.sock".to_string(),
};
// initialize the client.
let mut client = simple_pub_sub::client::Client::new(
simple_pub_sub::client::PubSubClient::Unix(client_type),
);
// 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(())
}examples/publish_tcp.rs (line 9)
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
async fn main() -> Result<(), String> {
let client_type = simple_pub_sub::client::PubSubTcpClient {
server: "localhost".to_string(),
port: 6480,
};
// initialize the client.
let mut client =
simple_pub_sub::client::Client::new(simple_pub_sub::client::PubSubClient::Tcp(client_type));
// 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(())
}sourcepub fn on_message(&mut self, callback: fn(_: String, _: Vec<u8>))
pub fn on_message(&mut self, callback: fn(_: String, _: Vec<u8>))
Sets the on_message callback function
Examples found in repository?
examples/subscribe_unix.rs (line 15)
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
async fn main() -> Result<(), String> {
let client_type = simple_pub_sub::client::PubSubUnixClient {
path: "/tmp/simple.sock".to_string(),
};
// initialize the client.
let mut client = simple_pub_sub::client::Client::new(
simple_pub_sub::client::PubSubClient::Unix(client_type),
);
// 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
examples/subscribe_tcp.rs (line 15)
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
async fn main() -> Result<(), String> {
let client_type = simple_pub_sub::client::PubSubTcpClient {
server: "localhost".to_string(),
port: 6480,
};
// initialize the client.
let mut client =
simple_pub_sub::client::Client::new(simple_pub_sub::client::PubSubClient::Tcp(client_type));
// 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(())
}sourcepub async fn connect(&mut self) -> Result<(), Error>
pub async fn connect(&mut self) -> Result<(), Error>
Connects to the server
Examples found in repository?
examples/subscribe_unix.rs (line 17)
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
async fn main() -> Result<(), String> {
let client_type = simple_pub_sub::client::PubSubUnixClient {
path: "/tmp/simple.sock".to_string(),
};
// initialize the client.
let mut client = simple_pub_sub::client::Client::new(
simple_pub_sub::client::PubSubClient::Unix(client_type),
);
// 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
examples/subscribe_tcp.rs (line 17)
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
async fn main() -> Result<(), String> {
let client_type = simple_pub_sub::client::PubSubTcpClient {
server: "localhost".to_string(),
port: 6480,
};
// initialize the client.
let mut client =
simple_pub_sub::client::Client::new(simple_pub_sub::client::PubSubClient::Tcp(client_type));
// 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(())
}examples/publish_unix.rs (line 11)
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
async fn main() -> Result<(), String> {
let client_type = simple_pub_sub::client::PubSubUnixClient {
path: "/tmp/simple.sock".to_string(),
};
// initialize the client.
let mut client = simple_pub_sub::client::Client::new(
simple_pub_sub::client::PubSubClient::Unix(client_type),
);
// 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(())
}examples/publish_tcp.rs (line 11)
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
async fn main() -> Result<(), String> {
let client_type = simple_pub_sub::client::PubSubTcpClient {
server: "localhost".to_string(),
port: 6480,
};
// initialize the client.
let mut client =
simple_pub_sub::client::Client::new(simple_pub_sub::client::PubSubClient::Tcp(client_type));
// 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(())
}sourcepub async fn post(self, msg: Msg) -> Result<Vec<u8>, Error>
pub async fn post(self, msg: Msg) -> Result<Vec<u8>, Error>
Sends the message to the given server and returns the ack the server could be either a tcp or unix server
sourcepub async fn publish(self, topic: String, message: Vec<u8>) -> Result<(), Error>
pub async fn publish(self, topic: String, message: Vec<u8>) -> Result<(), Error>
Publishes the message to the given topic
Examples found in repository?
examples/publish_unix.rs (lines 14-17)
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
async fn main() -> Result<(), String> {
let client_type = simple_pub_sub::client::PubSubUnixClient {
path: "/tmp/simple.sock".to_string(),
};
// initialize the client.
let mut client = simple_pub_sub::client::Client::new(
simple_pub_sub::client::PubSubClient::Unix(client_type),
);
// 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(())
}More examples
examples/publish_tcp.rs (lines 14-17)
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
async fn main() -> Result<(), String> {
let client_type = simple_pub_sub::client::PubSubTcpClient {
server: "localhost".to_string(),
port: 6480,
};
// initialize the client.
let mut client =
simple_pub_sub::client::Client::new(simple_pub_sub::client::PubSubClient::Tcp(client_type));
// 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(())
}sourcepub async fn query(self, topic: String) -> Result<String, Error>
pub async fn query(self, topic: String) -> Result<String, Error>
Sends the query message to the server
sourcepub async fn subscribe(self, topic: String) -> Result<(), Error>
pub async fn subscribe(self, topic: String) -> Result<(), Error>
subscribes to the given topic
Examples found in repository?
examples/subscribe_unix.rs (line 19)
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
async fn main() -> Result<(), String> {
let client_type = simple_pub_sub::client::PubSubUnixClient {
path: "/tmp/simple.sock".to_string(),
};
// initialize the client.
let mut client = simple_pub_sub::client::Client::new(
simple_pub_sub::client::PubSubClient::Unix(client_type),
);
// 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
examples/subscribe_tcp.rs (line 19)
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
async fn main() -> Result<(), String> {
let client_type = simple_pub_sub::client::PubSubTcpClient {
server: "localhost".to_string(),
port: 6480,
};
// initialize the client.
let mut client =
simple_pub_sub::client::Client::new(simple_pub_sub::client::PubSubClient::Tcp(client_type));
// 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§
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