Struct axum_server::Handle [−][src]
pub struct Handle { /* fields omitted */ }
Expand description
A struct that can be passed to a server for additional utilites.
Example
use axum::{
handler::get,
Router,
};
use axum_server::Handle;
use tokio::time::{sleep, Duration};
#[tokio::main]
async fn main() {
let app = Router::new().route("/", get(|| async { "Hello, World!" }));
let handle = Handle::new();
tokio::spawn(shutdown_in_twenty_secs(handle.clone()));
axum_server::bind("127.0.0.1:3000")
.handle(handle)
.serve(app)
.await
.unwrap();
}
async fn shutdown_in_twenty_secs(handle: Handle) {
sleep(Duration::from_secs(20)).await;
handle.shutdown();
}
Implementations
Signal server to shut down.
serve
function will return when shutdown is complete.
Signal server to gracefully shut down.
serve
function will return when graceful shutdown is complete.
Get addresses that are being listened.
Ordered by first bind
call to last bind
call.
Then ordered by first bind_rustls
call to last bind_rustls
call.
Always Some
after listening
returns.
Trait Implementations
Auto Trait Implementations
impl !RefUnwindSafe for Handle
impl !UnwindSafe for Handle
Blanket Implementations
Mutably borrows from an owned value. Read more
Instruments this type with the provided Span
, returning an
Instrumented
wrapper. Read more