Trait TransportFactory
pub trait TransportFactory: Send + Sync {
// Provided methods
fn create_transport_with_options(
&self,
options: TransportOptions,
) -> Arc<dyn Transport> { ... }
fn create_transport(&self, options: &ClientOptions) -> Arc<dyn Transport> { ... }
}Expand description
A factory creating transport instances.
Because options are potentially reused between different clients the
ClientOptions do not actually contain a transport but a factory object that
can create transports instead.
This factory has two methods. Although both methods have default implementations, the default
implementations call each other, so to avoid an infinitely recursive loop, types implementing
this trait must implement at least one of these methods. We recommend that implementors
implement only TransportFactory::create_transport_with_options because the other method,
TransportFactory::create_transport only exists for backwards compatibility.
Both factory methods create a new transport wrapped in an Arc. Because transports can be
wrapped in Arcs and those are clonable, Arc<Transport> is also a valid transport factory.
This for instance lets you put a Arc<TestTransport> directly into the options.
Provided Methods§
fn create_transport_with_options(
&self,
options: TransportOptions,
) -> Arc<dyn Transport>
fn create_transport_with_options( &self, options: TransportOptions, ) -> Arc<dyn Transport>
Create a transport with the given options.
Although a default implementation is provided for this trait method, we recommend that all
custom transport factories implement this method, as it is the way the SDK constructs the
transport. The default implementaton calls TransportFactory::create_transport as a
fallback.
fn create_transport(&self, options: &ClientOptions) -> Arc<dyn Transport>
👎Deprecated: use and implement create_transport_with_options instead
fn create_transport(&self, options: &ClientOptions) -> Arc<dyn Transport>
use and implement create_transport_with_options instead
The legacy method for creating a transport.
This method exists for backwards compatiblity with custom transport factories, which were
created before TransportFactory::create_transport_with_options was added, and thus only
implement this method.
New custom transport factories should not implement this method, as it is not called
from the SDK. A sensible default implementation, which forwards to
TransportFactory::create_transport_with_options is provided.
Implementations on Foreign Types§
§impl TransportFactory for DefaultTransportFactory
impl TransportFactory for DefaultTransportFactory
fn create_transport_with_options( &self, options: TransportOptions, ) -> Arc<dyn Transport>
§impl<T> TransportFactory for Arc<T>where
T: Transport,
impl<T> TransportFactory for Arc<T>where
T: Transport,
fn create_transport_with_options( &self, _: TransportOptions, ) -> Arc<dyn Transport>
Implementors§
impl<F> TransportFactory for F
This implementor is deprecated, as the closure is used as the deprecated
TransportFactory::create_transport method.
Use or create a TransportFactory which provides
TransportFactory::create_transport_with_options, instead.