Skip to main content

Server

Trait Server 

Source
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§

Source

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

Source

type Runtime: RuntimeTrait

The RuntimeTrait for this Server.

Source

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§

Source

fn accept(&mut self) -> impl Future<Output = Result<Self::Transport>> + Send

Asynchronously return a single Self::Transport from a Self::Listener. Must be implemented.

Source

fn runtime() -> Self::Runtime

Return this Server’s Runtime

Provided Methods§

Source

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.

Source

fn clean_up(self) -> impl Future<Output = ()> + Send

After the server has shut down, perform any housekeeping, eg unlinking a unix socket.

Source

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.

Source

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.

Source

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)].

Source

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.

Implementors§