pub struct Serve<L, M, S, B, E = TokioExecutor> { /* private fields */ }Expand description
Future returned by serve.
Implementations§
Source§impl<L, M, S, B, E> Serve<L, M, S, B, E>where
L: Listener,
impl<L, M, S, B, E> Serve<L, M, S, B, E>where
L: Listener,
Sourcepub fn with_graceful_shutdown<F>(
self,
signal: F,
) -> WithGracefulShutdown<L, M, S, F, B, E>
pub fn with_graceful_shutdown<F>( self, signal: F, ) -> WithGracefulShutdown<L, M, S, F, B, E>
Prepares a server to handle graceful shutdown when the provided future completes.
§Example
use axum::{Router, routing::get};
let router = Router::new().route("/", get(|| async { "Hello, World!" }));
let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await.unwrap();
axum::serve(listener, router)
.with_graceful_shutdown(shutdown_signal())
.await;
async fn shutdown_signal() {
// ...
}§Return Value
Similarly to serve, although this future resolves to io::Result<()>, it will never
error. It returns Ok(()) only after the signal future completes.
Sourcepub fn local_addr(&self) -> Result<<L as Listener>::Addr, Error>
pub fn local_addr(&self) -> Result<<L as Listener>::Addr, Error>
Returns the local address this server is bound to.
Sourcepub fn connection_lifetime_limits(
self,
limits: ConnectionLifetimeLimits,
) -> Serve<L, M, S, B, E>
pub fn connection_lifetime_limits( self, limits: ConnectionLifetimeLimits, ) -> Serve<L, M, S, B, E>
Apply per-connection ConnectionLifetimeLimits, bounding the lifetime of
individual connections.
This is useful for forcing clients to rotate connections — see
ConnectionLifetimeLimits for details and an example.
This method can be called before or after with_graceful_shutdown and
with_executor.
Sourcepub fn with_executor<E2>(self, executor: E2) -> Serve<L, M, S, B, E2>where
E2: Executor,
pub fn with_executor<E2>(self, executor: E2) -> Serve<L, M, S, B, E2>where
E2: Executor,
Provide a custom Executor to use for spawning connection tasks and
hyper’s internal tasks (e.g. HTTP/2).
The default is TokioExecutor. See the Executor docs for how to
implement a custom one.
This method can be called before or after with_graceful_shutdown.
§Example
use axum::{Router, routing::get, serve::Executor};
let router = Router::new().route("/", get(|| async { "Hello, World!" }));
let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await.unwrap();
axum::serve(listener, router)
.with_executor(MyExecutor)
.await;