This is the official PubNub Rust SDK repository.
PubNub takes care of the infrastructure and APIs needed for the realtime communication layer of your application. Work on your app's logic and let PubNub handle sending and receiving data across the world in less than 100ms.
Below you can find everything you need to start messaging!
You will need the publish and subscribe keys to authenticate your app. Get your keys from the Admin Portal.
Add pubnub
to your Rust project in the Cargo.toml
file:
```toml
[dependencies] pubnub = "0.2.1"
[dependencies] pubnub = { version = "0.2.1", features = ["full"] } ```
Try the following sample code to get up and running quickly!
```rust use pubnub::{Keyset, PubNubClientBuilder};
async fn main() -> Result<(), Box
let client = PubNubClientBuilder::with_reqwest_transport()
.with_keyset(Keyset {
subscribe_key,
publish_key: Some(publish_key),
secret_key: None,
})
.with_user_id("user_id")
.build()?;
client
.publish_message("hello world!")
.channel("my_channel")
.r#type("text-message")
.execute()
.await?;
Ok(())
} ```
You can find more examples in our examples directory!
The pubnub
crate is split into multiple features. You can enable or disable them in the Cargo.toml
file, like so:
```toml
[dependencies] pubnub = { version = "0.2.1", features = ["blocking", "access"] }
[dependencies] pubnub = { version = "0.2.1", features = ["parse_token"] } ```
| Feature name | Description | Available PubNub APIs |
| :------------ | :---------- | :------------- |
| full
| Enables all non-conflicting features | Configuration, Publish, Access Manager, Parse Token |
| default
| Enables default features: publish
, serde
, reqwest
, aescbc
, std
| Configuration, Publish |
| publish
| Enables Publish API | Configuration, Publish |
| access
| Enables Access Manager API | Configuration, Access Manager |
| parse_token
| Enables parsing Access Manager tokens | Configuration, Parse Token |
| serde
| Uses serde for serialization | n/a |
| reqwest
| Uses reqwest as a transport layer | n/a |
| blocking
| Enables blocking executions of APIs | n/a |
| aescbc
| Enables AES-CBC encryption | n/a |
| std
| Enables std
library | n/a |
The pubnub
crate is compatible with WebAssembly. You can use it in your Wasm project.
no_std
supportThe pubnub
crate is no_std
compatible. To use it in a no_std
environment, you have to disable the default
features and enable the ones you need, for example:
toml
[dependencies]
pubnub = { version = "0.2.1", default-features = false, features = ["serde", "publish",
"blocking"] }
The no_std
support is limited by the implementation details of the SDK.
The SDK uses the alloc
crate to allocate memory for some operations, which means that
certain targets aren't supported. Additionally, as we provide a synchronous API, we use
some parts of the alloc::sync
module, which is also not supported in certain no_std
environments.
Some SDK features aren't supported in a no_std
environment:
access
module (because of lack timestamp support)reqwest
transport (because of the reqwest implementation details)std
feature (because of the std
library)We depend on a random number generator to generate data for debugging purposes.
If you want to use the SDK in a no_std
environment, you'll have to provide
your own random number generator implementation for certain targets.
See more:
If you're having problems compiling this crate for more exotic targets, you can try to use the
extra_platforms
feature. Be aware that this feature is not supported and we do not recommend using it.
For more information about this feature. refer to Cargo.toml in the [features]
section.
If you need help or have a general question, contact support@pubnub.com.
This project is licensed under the MIT license.