Function hyper_serve::bind

source ยท
pub fn bind(addr: SocketAddr) -> Server
Expand description

Create a Server that will bind to provided address.

Examples found in repository?
examples/multiple_addresses.rs (line 21)
18
19
20
21
22
23
24
25
async fn start_server(addr: SocketAddr) {
    let app = Router::new().route("/", get(|| async { "Hello, world!" }));

    hyper_serve::bind(addr)
        .serve(app.into_make_service())
        .await
        .unwrap();
}
More examples
Hide additional examples
examples/remote_address.rs (line 16)
9
10
11
12
13
14
15
16
17
async fn main() {
    let app = Router::new()
        .route("/", get(handler))
        .into_make_service_with_connect_info::<SocketAddr>();

    let addr = SocketAddr::from(([127, 0, 0, 1], 3000));

    hyper_serve::bind(addr).serve(app).await.unwrap();
}
examples/http_and_https.rs (line 24)
19
20
21
22
23
24
25
26
27
28
async fn http_server() {
    let app = Router::new().route("/", get(http_handler));

    let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
    println!("http listening on {}", addr);
    hyper_serve::bind(addr)
        .serve(app.into_make_service())
        .await
        .unwrap();
}
examples/hello_world.rs (line 14)
9
10
11
12
13
14
15
16
17
18
async fn main() {
    let app = Router::new().route("/", get(|| async { "Hello, world!" }));

    let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
    println!("listening on {}", addr);
    hyper_serve::bind(addr)
        .serve(app.into_make_service())
        .await
        .unwrap();
}
examples/shutdown.rs (line 23)
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
async fn main() {
    let app = Router::new().route("/", get(|| async { "Hello, world!" }));

    let handle = Handle::new();

    // Spawn a task to shutdown server.
    tokio::spawn(shutdown(handle.clone()));

    let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
    println!("listening on {}", addr);
    hyper_serve::bind(addr)
        .handle(handle)
        .serve(app.into_make_service())
        .await
        .unwrap();

    println!("server is shut down");
}
examples/graceful_shutdown.rs (line 26)
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
async fn main() {
    let app = Router::new().route("/", get(|| async { "Hello, world!" }));

    let handle = Handle::new();

    // Spawn a task to gracefully shutdown server.
    tokio::spawn(graceful_shutdown(handle.clone()));

    let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
    println!("listening on {}", addr);
    hyper_serve::bind(addr)
        .handle(handle)
        .serve(app.into_make_service())
        .await
        .unwrap();

    println!("server is shut down");
}