Type Alias pubnub::PubNubGenericClient
source · pub type PubNubGenericClient<T, D> = PubNubClientInstance<PubNubMiddleware<T>, D>;Expand description
PubNub client
Client for PubNub API with support for all selected PubNub features.
The client is transport-layer-agnostic, so you can use any transport layer
that implements the [Transport] trait.
You can create clients using the PubNubClient::with_transport
You must provide a valid Keyset with pub/sub keys and a string User ID
to identify the client.
To see available methods, please refer to the PubNubClientInstance
documentation.
Examples
use pubnub::{PubNubClientBuilder, Keyset};
// note that `with_reqwest_transport` requires `reqwest` feature
// to be enabled (default)
let client = PubNubClientBuilder::with_reqwest_transport()
.with_keyset(Keyset {
publish_key: Some("pub-c-abc123"),
subscribe_key: "sub-c-abc123",
secret_key: None,
})
.with_user_id("my-user-id")
.build()?;
Using your own [Transport] implementation:
use pubnub::{PubNubClientBuilder, Keyset};
// note that MyTransport must implement the `Transport` trait
let transport = MyTransport::new();
let client = PubNubClientBuilder::with_transport(MyTransport)
.with_keyset(Keyset {
publish_key: Some("pub-c-abc123"),
subscribe_key: "sub-c-abc123",
secret_key: None,
})
.with_user_id("my-user-id")
.build()?;
Synchronization
Client is thread-safe and can be shared between threads. You don’t need to
wrap it in Arc or Mutex because it is already wrapped in Arc and uses
interior mutability for its internal state.
See also
Keyset
[Transport]
Aliased Type§
struct PubNubGenericClient<T, D> { /* private fields */ }