pub trait Server: Send + 'static {
    type Listener: Send + Sync + 'static;
    type Transport: AsyncRead + AsyncWrite + Unpin + Send + Sync + 'static;

    const DESCRIPTION: &'static str;
Show 14 methods fn accept(
        listener: &mut Self::Listener
    ) -> Pin<Box<dyn Future<Output = Result<Self::Transport>> + Send + '_>>; fn info(listener: &Self::Listener) -> Info; fn spawn(fut: impl Future<Output = ()> + Send + 'static); fn block_on(fut: impl Future<Output = ()> + 'static); fn peer_ip(transport: &Self::Transport) -> Option<IpAddr> { ... } fn set_nodelay(transport: &mut Self::Transport, nodelay: bool) { ... } fn set_ip_ttl(transport: &mut Self::Transport, ttl: u32) { ... } fn clean_up(
        _listener: Self::Listener
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'static>> { ... } fn build_listener<A>(config: &Config<Self, A>) -> Self::Listener
        A: Acceptor<Self::Transport>
, { ... } fn listener_from_tcp(_tcp: TcpListener) -> Self::Listener { ... } fn listener_from_unix(_tcp: UnixListener) -> Self::Listener { ... } fn handle_signals(
        _stopper: Stopper
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'static>> { ... } fn run<A, H>(config: Config<Self, A>, handler: H)
        A: Acceptor<Self::Transport>,
        H: Handler
, { ... } fn run_async<A, H>(
        config: Config<Self, A>,
        handler: H
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'static>>
        A: Acceptor<Self::Transport>,
        H: Handler
, { ... }
Expand description

The server trait, for standard network-based server implementations.

Required Associated Types

an async type like TcpListener or UnixListener. This trait imposes minimal constraints on the type.

the individual byte stream (AsyncRead+AsyncWrite) that http will be communicated over. This is often an async “stream” like TcpStream or UnixStream.

Required Associated Constants

The description of this server, to be appended to the Info and potentially logged.

Required Methods

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

Build an [Info] from the Self::Listener type. See [Info] for more details.

Runtime implementation hook for spawning a task.

Runtime implementation hook for blocking on a top level future.

Provided Methods

Optional method to return a peer ip address from a Self::Transport, if applicable. The default implementation returns None.

Optional method to set tcp nodelay to the provided value on the Self::Transport

Optional method to set ip ttl to the provided value on the Self::Transport

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

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::listener_from_tcp and Server::listener_from_unix.

Build a Self::Listener from a tcp listener. This is called by the Server::build_listener default implementation, and is mandatory if the default implementation is used.

Build a Self::Listener from a tcp listener. This is called by the Server::build_listener default implementation. You will want to tag an implementation of this with #[cfg(unix)].

Implementation hook for listening for any os signals and stopping the provided Stopper. The returned future will be spawned using Server::spawn

Run a trillium application from a sync context

Run a trillium application from an async context. The default implementation of this method contains the core logic of this Trait.