pub trait Server:
Sized
+ Send
+ Sync
+ 'static {
type Transport: Transport;
type Runtime: RuntimeTrait;
type UdpTransport: UdpTransport;
// Required methods
fn accept(&mut self) -> impl Future<Output = Result<Self::Transport>> + Send;
fn runtime() -> Self::Runtime;
// Provided methods
fn init(&self, info: &mut Info) { ... }
fn clean_up(self) -> impl Future<Output = ()> + Send { ... }
fn from_host_and_port(host: &str, port: u16) -> Self { ... }
fn from_tcp(tcp_listener: TcpListener) -> Self { ... }
fn from_unix(unix_listener: UnixListener) -> Self { ... }
fn handle_signals(_swansong: Swansong) -> impl Future<Output = ()> + Send { ... }
}Expand description
The server trait, for standard network-based server implementations.
Required Associated Types§
Sourcetype Transport: Transport
type Transport: Transport
the individual byte stream that http
will be communicated over. This is often an async “stream”
like TcpStream or UnixStream. See Transport
Sourcetype Runtime: RuntimeTrait
type Runtime: RuntimeTrait
The RuntimeTrait for this Server.
Sourcetype UdpTransport: UdpTransport
type UdpTransport: UdpTransport
The async UDP socket type for this server. Used by QUIC adapters
for HTTP/3 support. Runtimes that do not support UDP should set
this to ().
Required Methods§
Provided Methods§
Sourcefn init(&self, info: &mut Info)
fn init(&self, info: &mut Info)
Populate Info with data from this server, such as the bound socket address.
Called during server startup before any connections are accepted.
Sourcefn clean_up(self) -> impl Future<Output = ()> + Send
fn clean_up(self) -> impl Future<Output = ()> + Send
After the server has shut down, perform any housekeeping, eg unlinking a unix socket.
Sourcefn from_host_and_port(host: &str, port: u16) -> Self
fn from_host_and_port(host: &str, port: u16) -> Self
Build a listener from the config. The default logic for this
is described elsewhere. To override the default logic, server
implementations could potentially implement this directly. To
use this default logic, implement
Server::from_tcp and
Server::from_unix.
Sourcefn from_tcp(tcp_listener: TcpListener) -> Self
fn from_tcp(tcp_listener: TcpListener) -> Self
Build a Self::Listener from a tcp listener. This is called by
the Server::from_host_and_port default implementation, and
is mandatory if the default implementation is used.
Sourcefn from_unix(unix_listener: UnixListener) -> Self
fn from_unix(unix_listener: UnixListener) -> Self
Build a Self from a unix listener. This is called by
the Server::from_host_and_port default implementation. You
will want to tag an implementation of this with #[cfg(unix)].
Sourcefn handle_signals(_swansong: Swansong) -> impl Future<Output = ()> + Send
fn handle_signals(_swansong: Swansong) -> impl Future<Output = ()> + Send
Implementation hook for listening for any os signals and
stopping the provided Swansong. The returned future will be
spawned using RuntimeTrait::spawn
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.