pub struct Serve<M, S> { /* private fields */ }
Expand description
Future returned by serve
.
Implementations§
source§impl<M, S> Serve<M, S>
impl<M, S> Serve<M, S>
sourcepub fn with_graceful_shutdown<F>(
self,
signal: F,
) -> WithGracefulShutdown<M, S, F>
pub fn with_graceful_shutdown<F>( self, signal: F, ) -> WithGracefulShutdown<M, S, F>
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
.unwrap();
async fn shutdown_signal() {
// ...
}
sourcepub fn tcp_nodelay(self, nodelay: bool) -> Self
pub fn tcp_nodelay(self, nodelay: bool) -> Self
Instructs the server to set the value of the TCP_NODELAY
option on every accepted connection.
See also TcpStream::set_nodelay
.
§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)
.tcp_nodelay(true)
.await
.unwrap();
sourcepub fn local_addr(&self) -> Result<SocketAddr>
pub fn local_addr(&self) -> Result<SocketAddr>
Returns the local address this server is bound to.
Trait Implementations§
source§impl<M, S> IntoFuture for Serve<M, S>where
M: for<'a> Service<IncomingStream<'a>, Error = Infallible, Response = S> + Send + 'static,
for<'a> <M as Service<IncomingStream<'a>>>::Future: Send,
S: Service<Request, Response = Response, Error = Infallible> + Clone + Send + 'static,
S::Future: Send,
impl<M, S> IntoFuture for Serve<M, S>where
M: for<'a> Service<IncomingStream<'a>, Error = Infallible, Response = S> + Send + 'static,
for<'a> <M as Service<IncomingStream<'a>>>::Future: Send,
S: Service<Request, Response = Response, Error = Infallible> + Clone + Send + 'static,
S::Future: Send,
§type IntoFuture = ServeFuture
type IntoFuture = ServeFuture
Which kind of future are we turning this into?
source§fn into_future(self) -> Self::IntoFuture
fn into_future(self) -> Self::IntoFuture
Creates a future from a value. Read more
Auto Trait Implementations§
impl<M, S> !Freeze for Serve<M, S>
impl<M, S> RefUnwindSafe for Serve<M, S>where
M: RefUnwindSafe,
S: RefUnwindSafe,
impl<M, S> Send for Serve<M, S>
impl<M, S> Sync for Serve<M, S>
impl<M, S> Unpin for Serve<M, S>
impl<M, S> UnwindSafe for Serve<M, S>where
M: UnwindSafe,
S: UnwindSafe,
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more