pub trait ClientTransport: Send + Sync {
// Required methods
fn send(
&self,
method: &str,
params: &JsonObject,
) -> Pin<Box<dyn Future<Output = Result<JsonObject, TransportError>> + Send + '_>>;
fn notify(
&self,
method: &str,
params: &JsonObject,
) -> Pin<Box<dyn Future<Output = Result<(), TransportError>> + Send + '_>>;
}Expand description
Sends one request to the peer and returns its answer.
The port a client needs, and the only one. A transport implements it; the client does not know about sockets, headers, or framing.
The boxed form because a client’s exchange is chosen at run time from a
configuration and a test substitutes a different one — there is no
monomorphisation to win here, and holding a dyn is the honest shape.
Required Methods§
Sourcefn send(
&self,
method: &str,
params: &JsonObject,
) -> Pin<Box<dyn Future<Output = Result<JsonObject, TransportError>> + Send + '_>>
fn send( &self, method: &str, params: &JsonObject, ) -> Pin<Box<dyn Future<Output = Result<JsonObject, TransportError>> + Send + '_>>
Sends method with params and yields the peer’s answer.
§Errors
TransportError when the request could not be delivered or answered.
A client that waited forever would be a caller that cannot be
interrupted, so a non-answer is an error rather than a hang.
Sourcefn notify(
&self,
method: &str,
params: &JsonObject,
) -> Pin<Box<dyn Future<Output = Result<(), TransportError>> + Send + '_>>
fn notify( &self, method: &str, params: &JsonObject, ) -> Pin<Box<dyn Future<Output = Result<(), TransportError>> + Send + '_>>
Sends method with params and expects no answer.
Separate from send because a notification is not a
request that tolerates a missing reply — it has no id at all, and a
transport that waited for one would wait forever, because a conforming
peer correctly sends nothing. The notifications/initialized that ends
the handshake is one of these, so a client that could not send it had no
way to finish connecting.
§Errors
TransportError when the notification could not be written. Nothing
else is possible: there is no reply to be wrong about.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".