alloy_transport/
connect.rs

1use crate::{BoxTransport, TransportError};
2use futures_utils_wasm::impl_future;
3
4/// Connection details for a transport.
5///
6/// This object captures the information necessary to establish a transport,
7/// and may encapsulate reconnection logic.
8///
9/// ## Why implement `TransportConnect`?
10///
11/// Users may want to implement transport-connect for the following reasons:
12/// - You want to customize a `reqwest::Client` before using it.
13/// - You need to provide special authentication information to a remote provider.
14/// - You have implemented a custom [`Transport`](crate::Transport).
15/// - You require a specific websocket reconnection strategy.
16pub trait TransportConnect: Sized + Send + Sync + 'static {
17    /// Returns `true` if the transport connects to a local resource.
18    fn is_local(&self) -> bool;
19
20    /// Connect to the transport, returning a `Transport` instance.
21    fn get_transport(&self) -> impl_future!(<Output = Result<BoxTransport, TransportError>>);
22}