Trait trillium_testing::Server
pub trait Server: Sized + Send + Sync + 'static {
type Transport: Transport;
const DESCRIPTION: &'static str;
// Required methods
fn accept(
&mut self,
) -> Pin<Box<dyn Future<Output = Result<Self::Transport, Error>> + Send + '_>>;
fn info(&self) -> Info;
fn spawn(fut: impl Future<Output = ()> + Send + 'static);
fn block_on(fut: impl Future<Output = ()> + 'static);
// Provided methods
fn clean_up(self) -> Pin<Box<dyn Future<Output = ()> + Send>> { ... }
fn build_listener<A>(config: &Config<Self, A>) -> Self
where A: Acceptor<Self::Transport> { ... }
fn listener_from_tcp(_tcp: TcpListener) -> Self { ... }
fn listener_from_unix(_tcp: UnixListener) -> Self { ... }
fn handle_signals(
_stopper: Stopper,
) -> Pin<Box<dyn Future<Output = ()> + Send>> { ... }
fn run<A, H>(config: Config<Self, A>, handler: H)
where A: Acceptor<Self::Transport>,
H: Handler { ... }
fn run_async<A, H>(
config: Config<Self, A>,
handler: H,
) -> Pin<Box<dyn Future<Output = ()> + Send>>
where A: Acceptor<Self::Transport>,
H: Handler { ... }
}
Expand description
The server trait, for standard network-based server implementations.
Required Associated Types§
Required Associated Constants§
const DESCRIPTION: &'static str
const DESCRIPTION: &'static str
The description of this server, to be appended to the Info and potentially logged.
Required Methods§
fn accept(
&mut self,
) -> Pin<Box<dyn Future<Output = Result<Self::Transport, Error>> + Send + '_>>
fn accept( &mut self, ) -> Pin<Box<dyn Future<Output = Result<Self::Transport, Error>> + Send + '_>>
Asynchronously return a single Self::Transport
from a
Self::Listener
. Must be implemented.
Provided Methods§
fn clean_up(self) -> Pin<Box<dyn Future<Output = ()> + Send>>
fn clean_up(self) -> Pin<Box<dyn Future<Output = ()> + Send>>
After the server has shut down, perform any housekeeping, eg unlinking a unix socket.
fn build_listener<A>(config: &Config<Self, A>) -> Selfwhere
A: Acceptor<Self::Transport>,
fn build_listener<A>(config: &Config<Self, A>) -> Selfwhere
A: Acceptor<Self::Transport>,
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
.
fn listener_from_tcp(_tcp: TcpListener) -> Self
fn listener_from_tcp(_tcp: TcpListener) -> Self
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.
fn listener_from_unix(_tcp: UnixListener) -> Self
fn listener_from_unix(_tcp: UnixListener) -> Self
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)].
fn handle_signals(_stopper: Stopper) -> Pin<Box<dyn Future<Output = ()> + Send>>
fn handle_signals(_stopper: Stopper) -> Pin<Box<dyn Future<Output = ()> + Send>>
Implementation hook for listening for any os signals and
stopping the provided [Stopper
]. The returned future will be
spawned using Server::spawn
fn run<A, H>(config: Config<Self, A>, handler: H)
fn run<A, H>(config: Config<Self, A>, handler: H)
Run a trillium application from a sync context