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

Create a Handle.

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.

Wait until server starts listening on all addresses.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Returns the “default value” for a type. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.