Skip to main content

CallbackExchange

Trait CallbackExchange 

Source
pub trait CallbackExchange {
    // Required method
    fn exchange(
        &self,
        method: &str,
        params: &JsonObject,
    ) -> impl Future<Output = Result<JsonObject, ExchangeError>> + Send;
}
Expand description

A round trip to the peer that a server-initiated request needs.

The port belongs to the consumer. It is declared here rather than in an adapter because the shape of what a server needs to ask a peer is a decision this module makes: a method name, a params object, and an answer back. A transport implements it; nothing in adapters/ defines it.

Not object-safe by design — it is an RPITIT async fn, so a caller that knows its concrete exchange gets it inlined with no allocation. Callers that genuinely need a boxed one get DynExchange.

Required Methods§

Source

fn exchange( &self, method: &str, params: &JsonObject, ) -> impl Future<Output = Result<JsonObject, ExchangeError>> + Send

Sends method to the peer and returns its answer.

The implementation owns framing: it knows the negotiated revision, it knows the method’s wire name, and it parses the reply. Nothing above this trait ever sees a byte.

§Errors

ExchangeError when the request could not be delivered or the peer did not answer. Whether a non-answer is an error or a hang is the adapter’s decision, and a server that waits forever is a server whose connection never closes.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§