alloy_transport

Trait Transport

source
pub trait Transport:
    Service<RequestPacket, Response = ResponsePacket, Error = TransportError, Future = TransportFut<'static>>
    + Send
    + Sync
    + 'static {
    // Provided methods
    fn boxed(self) -> BoxTransport
       where Self: Sized + Clone { ... }
    fn as_boxed(&self) -> BoxTransport
       where Self: Sized + Clone { ... }
}
Expand description

A Transport manages the JSON-RPC request/response lifecycle.

Transports should be instantiated via the TransportConnect trait.

Transports are responsible for the following:

  • Communicating with the RPC server.
  • Managing any ongoing connection or communication resource.
  • Associating responses with requests.
  • Associating notifications with subscriptions.

As a result, a Transport may be a simple HTTP client, or a collection of long-lived tasks.

§Implementing Transport

This trait is blanket implemented for all appropriate types. To implement this trait, you must implement the tower::Service trait with the appropriate associated types. It cannot be implemented directly.

§⚠️ Always implement Clone ⚠️

Clone is not a bound on Transport, however, transports generally may not be used as expected unless they implement Clone. For example, only cloneable transports may be used by the RpcClient in alloy-rpc-client to send RPC requests, and BoxTransport may only be used to type-erase cloneable transports.

If you are implementing a transport, make sure it is Clone.

Provided Methods§

source

fn boxed(self) -> BoxTransport
where Self: Sized + Clone,

Convert this transport into a boxed trait object.

source

fn as_boxed(&self) -> BoxTransport
where Self: Sized + Clone,

Make a boxed trait object by cloning this transport.

Implementors§

source§

impl<T> Transport for T
where T: Service<RequestPacket, Response = ResponsePacket, Error = TransportError, Future = TransportFut<'static>> + Send + Sync + 'static,