Crates.io | pubnub-core |
lib.rs | pubnub-core |
version | 0.1.0 |
source | src |
created_at | 2020-03-23 21:14:13.593489 |
updated_at | 2020-03-23 21:14:13.593489 |
description | PubNub core crate, modular and composable |
homepage | https://www.pubnub.com/ |
repository | https://github.com/pubnub/rust |
max_upload_size | |
id | 221909 |
size | 70,787 |
The PubNub Rust SDK is based on Tokio 0.2
. This library uses HTTP/2
to communicate with the PubNub Edge Messaging Network.
Supports Rust 1.39.0 and higher.
First you'll need to add the dependency to your project.
Easily add PubNub lib to your Cargo.toml
file.
[dependencies.pubnub_hyper]
git = "https://github.com/pubnub/rust"
Try the following sample code to get up and running quickly.
use futures_util::stream::StreamExt;
use pubnub_hyper::runtime::tokio_global::TokioGlobal;
use pubnub_hyper::transport::hyper::Hyper;
use pubnub_hyper::{core::json::object, Builder};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let transport = Hyper::new()
.publish_key("demo")
.subscribe_key("demo")
.build()?;
let mut pubnub = Builder::new()
.transport(transport)
.runtime(TokioGlobal)
.build();
let message = object! {
"username" => "JoeBob",
"content" => "Hello, world!",
};
let mut stream = pubnub.subscribe("my-channel").await;
let timetoken = pubnub.publish("my-channel", message).await?;
println!("timetoken = {:?}", timetoken);
let received = stream.next().await;
println!("received = {:?}", received);
Ok(())
}
You can find these examples in the ./pubnub-hyper/examples
directory.
Explore the usage patterns available in each of the examples.
You can easily run each of the examples with these cargo commands:
cargo run --example publish-subscribe