SocketService

Trait SocketService 

Source
pub trait SocketService: 'static {
    type RequestDeserializer: Deserializer<Message: Message> + 'static;
    type ResponseSerializer: Serializer<Message: Message> + 'static;
    type ConnectionService: ConnectionService<Request = <Self::RequestDeserializer as Deserializer>::Message, Response = <Self::ResponseSerializer as Serializer>::Message>;
    type Stream: AsyncRead + AsyncWrite + Unpin + Send + 'static;

    // Required methods
    fn deserializer(&self) -> Self::RequestDeserializer;
    fn serializer(&self) -> Self::ResponseSerializer;
    fn new_connection_service(
        &self,
        address: SocketAddr,
    ) -> Self::ConnectionService;
    fn accept_stream(
        &self,
        stream: TcpStream,
    ) -> impl Future<Output = Result<Self::Stream>> + Send + 'static;
}
Expand description

SocketService receives connections and produces ConnectionServices.

The SocketService is notified when a new connection is established. It is given the address of the remote peer and it returns a ConnectionService for that connection. You can think of this as the “connection factory” for your server. It is the “top” of your service stack.

Required Associated Types§

Source

type RequestDeserializer: Deserializer<Message: Message> + 'static

The type of deserializer for incoming messages.

Source

type ResponseSerializer: Serializer<Message: Message> + 'static

The type of serializer for outgoing messages.

Source

type ConnectionService: ConnectionService<Request = <Self::RequestDeserializer as Deserializer>::Message, Response = <Self::ResponseSerializer as Serializer>::Message>

The type of connection service that will be created for each connection.

Source

type Stream: AsyncRead + AsyncWrite + Unpin + Send + 'static

The type of stream that will be used for the connection. Something like a tokio::net::TcpStream or tokio_rustls::TlsStream<tokio::net::TcpStream>.

Required Methods§

Source

fn deserializer(&self) -> Self::RequestDeserializer

Create a new deserializer for incoming messages.

Source

fn serializer(&self) -> Self::ResponseSerializer

Create a new serializer for outgoing messages.

Source

fn new_connection_service(&self, address: SocketAddr) -> Self::ConnectionService

Create a new ConnectionService for a new connection.

Source

fn accept_stream( &self, stream: TcpStream, ) -> impl Future<Output = Result<Self::Stream>> + Send + 'static

Accept and possibly customize the stream for a new connection. This is where you can wrap the stream with TLS.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§