1use crate::address::SocketAddress;
2
3use rama_core::{Service, error::BoxError};
4
5pub trait SocketService: Send + Sync + 'static {
11 type Socket: Send + 'static;
13 type Error: Into<BoxError> + Send + 'static;
15
16 fn bind_socket_with_address(
18 &self,
19 addr: impl Into<SocketAddress>,
20 ) -> impl Future<Output = Result<Self::Socket, Self::Error>> + Send + '_;
21}
22
23impl<S, Socket> SocketService for S
24where
25 S: Service<SocketAddress, Output = Socket, Error: Into<BoxError> + Send + 'static>,
26 Socket: Send + 'static,
27{
28 type Socket = Socket;
29 type Error = S::Error;
30
31 fn bind_socket_with_address(
32 &self,
33 addr: impl Into<SocketAddress>,
34 ) -> impl Future<Output = Result<Self::Socket, Self::Error>> + Send + '_ {
35 self.serve(addr.into())
36 }
37}