pub struct Client { /* private fields */ }
Expand description

Client is a Clonable handle to NATS connection. Client should not be created directly. Instead, one of two methods can be used: crate::connect and crate::ConnectOptions::connect

Implementations

Returns last received info from the server.

Examples

let client = async_nats::connect("demo.nats.io").await?;
println!("info: {:?}", client.server_info());

Returns true if the server version is compatible with the version components.

Examples
let client = async_nats::connect("demo.nats.io").await?;
assert!(client.is_server_compatible(2, 8, 4));

Sends the request with headers.

Examples
let client = async_nats::connect("demo.nats.io").await?;
let mut headers = async_nats::HeaderMap::new();
headers.insert("Key", "Value");
client.request_with_headers("service".into(), headers, "data".into()).await?;

Sends the request created by the Request.

Examples
let client = async_nats::connect("demo.nats.io").await?;
let request = async_nats::Request::new().payload("data".into());
client.send_request("service".into(), request).await?;

Create a new globally unique inbox which can be used for replies.

Examples
let reply = nc.new_inbox();
let rsub = nc.subscribe(reply).await?;

Returns the current state of the connection.

Examples
let client = async_nats::connect("demo.nats.io").await?;
println!("connection state: {}", client.connection_state());

Trait Implementations

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Should always be Self
The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more