### Handle::listening - Wait for Server to Start Source: https://context7.com/programatik29/axum-server/llms.txt Waits for the server to bind and returns the actual listening address. Returns `None` if binding fails. ```APIDOC ## Handle::listening - Wait for Server to Start ### Description Waits for the server to bind and returns the actual listening address. Returns `None` if binding fails. ### Method `Handle::listening()` ### Endpoint N/A (Method on Handle struct) ### Parameters None ### Request Example ```rust use axum::{routing::get, Router}; use axum_server::Handle; use std::net::SocketAddr; let handle = Handle::new(); let server_handle = handle.clone(); tokio::spawn(async move { let app = Router::new().route("/", get(|| async { "Hello, world!" })); let addr = SocketAddr::from(([127, 0, 0, 1], 0)); // Port 0 = auto-assign axum_server::bind(addr) .handle(server_handle) .serve(app.into_make_service()) .await .unwrap(); }); // Wait for server to start and get actual bound address let addr = handle.listening().await.unwrap(); println!("Server is listening on {}", addr); ``` ### Response - `SocketAddr` - The actual address the server is listening on. - `None` - If binding fails. ``` -------------------------------- ### Run HTTP and HTTPS Servers Concurrently Source: https://context7.com/programatik29/axum-server/llms.txt This example demonstrates running both HTTP and HTTPS servers simultaneously, with the HTTP server redirecting all traffic to the HTTPS server. It requires TLS certificates to be present. ```rust use axum::{http::uri::Uri, response::Redirect, routing::get, Router}; use axum_server::tls_rustls::RustlsConfig; use std::net::SocketAddr; #[tokio::main] async fn main() { let http = tokio::spawn(http_server()); let https = tokio::spawn(https_server()); let _ = tokio::join!(http, https); } 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); axum_server::bind(addr) .serve(app.into_make_service()) .await .unwrap(); } async fn http_handler(uri: Uri) -> Redirect { let uri = format!("https://127.0.0.1:3443{}", uri.path()); Redirect::temporary(&uri) } async fn https_server() { let app = Router::new().route("/", get(|| async { "Hello, world!" })); let config = RustlsConfig::from_pem_file( "examples/self-signed-certs/cert.pem", "examples/self-signed-certs/key.pem", ) .await .unwrap(); let addr = SocketAddr::from(([127, 0, 0, 1], 3443)); println!("HTTPS listening on {}", addr); axum_server::bind_rustls(addr, config) .serve(app.into_make_service()) .await .unwrap(); } ``` -------------------------------- ### Wait for Server to Start and Get Listening Address Source: https://context7.com/programatik29/axum-server/llms.txt Waits for the server to bind to a port and returns the actual listening address. This is useful when the server is configured to auto-assign a port (port 0). ```rust use axum::{routing::get, Router}; use axum_server::Handle; use std::net::SocketAddr; #[tokio::main] async fn main() { let handle = Handle::new(); let server_handle = handle.clone(); tokio::spawn(async move { let app = Router::new().route("/", get(|| async { "Hello, world!" })); let addr = SocketAddr::from(([127, 0, 0, 1], 0)); // Port 0 = auto-assign axum_server::bind(addr) .handle(server_handle) .serve(app.into_make_service()) .await .unwrap(); }); // Wait for server to start and get actual bound address let addr = handle.listening().await.unwrap(); println!("Server is listening on {}", addr); } ``` -------------------------------- ### POST /api/users Source: https://context7.com/programatik29/axum-server/llms.txt Creates a new HTTP server bound to the specified socket address. This is the primary entry point for starting an Axum application with axum-server. ```APIDOC ## bind - Create HTTP Server ### Description Creates a new HTTP server bound to the specified socket address. This is the primary entry point for starting an Axum application with axum-server. ### Method POST ### Endpoint /api/users ### Parameters #### Path Parameters - **userId** (string) - Required - The ID of the user to retrieve. #### Query Parameters - **include_details** (boolean) - Optional - Whether to include detailed user information. ### Request Body - **username** (string) - Required - The username for the new user. - **email** (string) - Required - The email address for the new user. ### Request Example ```json { "username": "johndoe", "email": "john.doe@example.com" } ``` ### Response #### Success Response (200) - **id** (string) - The unique identifier for the created user. - **username** (string) - The username of the created user. - **email** (string) - The email address of the created user. #### Response Example ```json { "id": "user-12345", "username": "johndoe", "email": "john.doe@example.com" } ``` ``` -------------------------------- ### Handle::connection_count - Get Active Connections Source: https://context7.com/programatik29/axum-server/llms.txt Returns the current number of active connections being handled by the server. ```APIDOC ## Handle::connection_count - Get Active Connections ### Description Returns the current number of active connections being handled by the server. ### Method `Handle::connection_count()` ### Endpoint N/A (Method on Handle struct) ### Parameters None ### Request Example ```rust use axum_server::Handle; use std::net::SocketAddr; async fn monitor_connections(handle: Handle) { loop { let count = handle.connection_count(); println!("Current connections: {}", count); tokio::time::sleep(std::time::Duration::from_secs(5)).await; } } ``` ### Response - `usize` - The number of active connections. ``` -------------------------------- ### Basic Hello World Axum Server Source: https://github.com/programatik29/axum-server/blob/master/README.md A simple hello world application using axum-server. Ensure tokio is set up for async execution. The server binds to a specified address and serves the Axum application. ```rust use axum::{routing::get, Router}; use std::net::SocketAddr; #[tokio::main] 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); axum_server::bind(addr) .serve(app.into_make_service()) .await .unwrap(); } ``` -------------------------------- ### from_tcp - Create Server from Existing TcpListener Source: https://context7.com/programatik29/axum-server/llms.txt Creates a server from an existing `std::net::TcpListener`, useful when you need to bind the listener separately or pass it from another process. ```APIDOC ## from_tcp - Create Server from Existing TcpListener ### Description Creates a server from an existing `std::net::TcpListener`, useful when you need to bind the listener separately or pass it from another process. ### Method POST ### Endpoint /api/listeners ### Parameters #### Request Body - **listener_config** (object) - Required - Configuration for the TCP listener. - **address** (string) - Required - The address to bind the listener to (e.g., "127.0.0.1:3000"). ### Request Example ```json { "listener_config": { "address": "127.0.0.1:3000" } } ``` ### Response #### Success Response (200) - **message** (string) - A confirmation message indicating the server was created from the listener. #### Response Example ```json { "message": "Server created successfully from TcpListener." } ``` ``` -------------------------------- ### Create Server from TcpListener Source: https://context7.com/programatik29/axum-server/llms.txt Creates a server from an existing `std::net::TcpListener`. This is useful when you need to bind the listener separately or pass it from another process. ```rust use axum::{routing::get, Router}; use std::net::{SocketAddr, TcpListener}; #[tokio::main] async fn main() { let app = Router::new().route("/", get(|| async { "Hello, world!" })); let addr = SocketAddr::from(([127, 0, 0, 1], 3000)); let listener = TcpListener::bind(addr).unwrap(); println!("listening on {}", addr); axum_server::from_tcp(listener) .unwrap() .serve(app.into_make_service()) .await .unwrap(); } ``` -------------------------------- ### Unix Socket Binding (Unix only) Source: https://context7.com/programatik29/axum-server/llms.txt Creates a server that listens on a Unix domain socket, useful for local IPC or container deployments with socket activation. ```APIDOC ## Unix Socket Binding (Unix only) ### Description Creates a server that listens on a Unix domain socket, useful for local IPC or container deployments with socket activation. ### Method POST ### Endpoint /api/unix-socket ### Parameters #### Request Body - **socket_path** (string) - Required - The path for the Unix domain socket (e.g., "/tmp/axum-server.sock"). ### Request Example ```json { "socket_path": "/tmp/axum-server.sock" } ``` ### Response #### Success Response (200) - **message** (string) - A confirmation message indicating the server is listening on the Unix socket. - **socket_path** (string) - The path of the Unix domain socket. #### Response Example ```json { "message": "Server listening on Unix socket.", "socket_path": "/tmp/axum-server.sock" } ``` ### Testing Test with: `curl --unix-socket /tmp/axum-server.sock http://localhost` ``` -------------------------------- ### RustlsConfig: Create TLS Configuration from PEM Files Source: https://context7.com/programatik29/axum-server/llms.txt Use this method to create a TLS configuration from separate certificate and private key PEM files. This is the most common way to configure TLS. ```rust use axum_server::tls_rustls::RustlsConfig; use rustls::ServerConfig; use std::sync::Arc; #[tokio::main] async fn main() { // From PEM files (most common) let config = RustlsConfig::from_pem_file( "path/to/cert.pem", "path/to/key.pem", ).await.unwrap(); // From PEM certificate chain file let config = RustlsConfig::from_pem_chain_file( "path/to/chain.pem", "path/to/key.pem", ).await.unwrap(); // From PEM data in memory let cert_pem = std::fs::read("path/to/cert.pem").unwrap(); let key_pem = std::fs::read("path/to/key.pem").unwrap(); let config = RustlsConfig::from_pem(cert_pem, key_pem).await.unwrap(); // From DER-encoded data let cert_der = vec![std::fs::read("path/to/cert.der").unwrap()]; let key_der = std::fs::read("path/to/key.der").unwrap(); let config = RustlsConfig::from_der(cert_der, key_der).await.unwrap(); // From existing rustls ServerConfig let server_config = Arc::new(ServerConfig::builder() .with_no_client_auth() .with_single_cert(vec![], rustls_pki_types::PrivateKeyDer::try_from(vec![]).unwrap()) .unwrap()); let config = RustlsConfig::from_config(server_config); } ``` -------------------------------- ### TLS with Rustls - bind_rustls Source: https://context7.com/programatik29/axum-server/llms.txt Creates an HTTPS server using rustls for TLS. Requires the `tls-rustls` feature. ```APIDOC ## TLS with Rustls - bind_rustls ### Description Creates an HTTPS server using rustls for TLS. Requires the `tls-rustls` feature. ### Method `axum_server::bind_rustls(addr: impl ToSocketAddrs, config: RustlsConfig)` ### Endpoint N/A (Function to bind server) ### Parameters - **addr** (impl ToSocketAddrs) - The address to bind the server to. - **config** (RustlsConfig) - The TLS configuration for rustls. ### Request Body N/A ### Request Example ```rust use axum::{routing::get, Router}; use axum_server::tls_rustls::RustlsConfig; use std::net::SocketAddr; #[tokio::main] async fn main() { let app = Router::new().route("/", get(|| async { "Hello, world!" })); let config = RustlsConfig::from_pem_file( "examples/self-signed-certs/cert.pem", "examples/self-signed-certs/key.pem", ) .await .unwrap(); let addr = SocketAddr::from(([127, 0, 0, 1], 3000)); println!("listening on {}", addr); axum_server::bind_rustls(addr, config) .serve(app.into_make_service()) .await .unwrap(); } ``` ### Response N/A (This function returns a `Server` that needs to be `serve`d) ### Error Handling - `RustlsConfig::from_pem_file` can return an error if the certificate or key files are not found or are invalid. ``` -------------------------------- ### OpenSSLConfig: Create HTTPS Server with OpenSSL Source: https://context7.com/programatik29/axum-server/llms.txt This snippet demonstrates how to create an HTTPS server using OpenSSL for TLS. Ensure the `tls-openssl` feature is enabled for your axum-server dependency. ```rust use axum::{routing::get, Router}; use axum_server::tls_openssl::OpenSSLConfig; use std::net::SocketAddr; #[tokio::main] async fn main() { let app = Router::new().route("/", get(|| async { "Hello, world!" })); let config = OpenSSLConfig::from_pem_file( "examples/self-signed-certs/cert.pem", "examples/self-signed-certs/key.pem", ) .unwrap(); let addr = SocketAddr::from(([127, 0, 0, 1], 3000)); println!("listening on {}", addr); axum_server::bind_openssl(addr, config) .serve(app.into_make_service()) .await .unwrap(); } ``` -------------------------------- ### OpenSSLConfig: TLS Configuration Options Source: https://context7.com/programatik29/axum-server/llms.txt Provides methods to create OpenSSL TLS configurations from PEM files, DER data, or a custom `SslAcceptorBuilder` for advanced customization. ```rust use axum_server::tls_openssl::OpenSSLConfig; use openssl::ssl::{SslAcceptor, SslMethod}; use std::convert::TryFrom; fn main() { // From PEM files let config = OpenSSLConfig::from_pem_file( "path/to/cert.pem", "path/to/key.pem", ).unwrap(); // From PEM certificate chain let config = OpenSSLConfig::from_pem_chain_file( "path/to/chain.pem", "path/to/key.pem", ).unwrap(); // From DER-encoded data let cert_der = std::fs::read("path/to/cert.der").unwrap(); let key_der = std::fs::read("path/to/key.der").unwrap(); let config = OpenSSLConfig::from_der(&cert_der, &key_der).unwrap(); // From custom SslAcceptorBuilder for advanced configuration let mut tls_builder = SslAcceptor::mozilla_modern_v5(SslMethod::tls()).unwrap(); tls_builder.set_certificate_chain_file("path/to/chain.pem").unwrap(); tls_builder.set_private_key_file("path/to/key.pem", openssl::ssl::SslFiletype::PEM).unwrap(); let config = OpenSSLConfig::try_from(tls_builder).unwrap(); } ``` -------------------------------- ### Create HTTPS Server with Rustls Source: https://context7.com/programatik29/axum-server/llms.txt Binds and serves an Axum application over HTTPS using the rustls library for TLS. Requires the `tls-rustls` feature to be enabled and valid certificate and key files. ```rust use axum::{routing::get, Router}; use axum_server::tls_rustls::RustlsConfig; use std::net::SocketAddr; #[tokio::main] async fn main() { let app = Router::new().route("/", get(|| async { "Hello, world!" })); let config = RustlsConfig::from_pem_file( "examples/self-signed-certs/cert.pem", "examples/self-signed-certs/key.pem", ) .await .unwrap(); let addr = SocketAddr::from(([127, 0, 0, 1], 3000)); println!("listening on {}", addr); axum_server::bind_rustls(addr, config) .serve(app.into_make_service()) .await .unwrap(); } ``` -------------------------------- ### Handle::shutdown - Immediate Shutdown Source: https://context7.com/programatik29/axum-server/llms.txt Immediately shuts down the server without waiting for connections to finish. ```APIDOC ## Handle::shutdown - Immediate Shutdown ### Description Immediately shuts down the server without waiting for connections to finish. ### Method `Handle::shutdown()` ### Endpoint N/A (Method on Handle struct) ### Parameters None ### Request Example ```rust use axum_server::Handle; use std::net::SocketAddr; async fn trigger_shutdown(handle: Handle) { // Immediately terminate all connections and stop the server handle.shutdown(); } ``` ### Response None ``` -------------------------------- ### Unix Socket Binding Source: https://context7.com/programatik29/axum-server/llms.txt Creates a server that listens on a Unix domain socket. This is useful for local IPC or container deployments with socket activation. Test with: curl --unix-socket /tmp/axum-server.sock http://localhost ```rust use axum::{routing::get, Router}; use std::os::unix::net::SocketAddr; #[tokio::main] async fn main() { let app = Router::new().route("/", get(|| async { "Hello, world!" })); let addr = SocketAddr::from_pathname("/tmp/axum-server.sock").unwrap(); println!("listening on {}", addr.as_pathname().unwrap().display()); axum_server::bind(addr) .serve(app.into_make_service()) .await .unwrap(); } // Test with: curl --unix-socket /tmp/axum-server.sock http://localhost ``` -------------------------------- ### Immediate Server Shutdown Source: https://context7.com/programatik29/axum-server/llms.txt Immediately terminates all active connections and stops the server without waiting for ongoing requests to complete. ```rust use axum_server::Handle; use std::net::SocketAddr; async fn trigger_shutdown(handle: Handle) { // Immediately terminate all connections and stop the server handle.shutdown(); } ``` -------------------------------- ### Access Client IP Address with ConnectInfo Source: https://context7.com/programatik29/axum-server/llms.txt Utilize `into_make_service_with_connect_info` to extract the client's `SocketAddr` within your Axum handlers. This requires the `ConnectInfo` extractor. ```rust use axum::{extract::ConnectInfo, routing::get, Router}; use std::net::SocketAddr; #[tokio::main] async fn main() { let app = Router::new() .route("/", get(handler)) .into_make_service_with_connect_info::(); let addr = SocketAddr::from(([127, 0, 0, 1], 3000)); axum_server::bind(addr).serve(app).await.unwrap(); } async fn handler(ConnectInfo(addr): ConnectInfo) -> String { format!("Your IP address is: {}", addr) } ``` -------------------------------- ### Monitor Active Server Connections Source: https://context7.com/programatik29/axum-server/llms.txt Periodically retrieves and prints the current number of active connections being handled by the server. Useful for monitoring server load. ```rust use axum_server::Handle; use std::net::SocketAddr; async fn monitor_connections(handle: Handle) { loop { let count = handle.connection_count(); println!("Current connections: {}", count); tokio::time::sleep(std::time::Duration::from_secs(5)).await; } } ``` -------------------------------- ### Server::http2_only - HTTP/2 Only Mode Source: https://context7.com/programatik29/axum-server/llms.txt Configures the server to accept only HTTP/2 connections, rejecting HTTP/1 requests. ```APIDOC ## Server::http2_only - HTTP/2 Only Mode ### Description Configures the server to accept only HTTP/2 connections, rejecting HTTP/1 requests. ### Method PUT ### Endpoint /api/server/protocol ### Parameters #### Request Body - **protocol** (string) - Required - Set to "http2" to enable HTTP/2 only mode. ### Request Example ```json { "protocol": "http2" } ``` ### Response #### Success Response (200) - **message** (string) - Confirmation that the server is configured for HTTP/2 only. #### Response Example ```json { "message": "Server configured for HTTP/2 only." } ``` ``` -------------------------------- ### HTTP/2 Only Mode Source: https://context7.com/programatik29/axum-server/llms.txt Configures the server to accept only HTTP/2 connections, rejecting HTTP/1 requests. ```rust use axum::{routing::get, Router}; use axum_server::Server; use std::net::SocketAddr; #[tokio::main] async fn main() { let app = Router::new().route("/", get(|| async { "Hello, world!" })); let addr = SocketAddr::from(([127, 0, 0, 1], 3000)); Server::bind(addr) .http2_only() .serve(app.into_make_service()) .await .unwrap(); } ``` -------------------------------- ### Graceful Server Shutdown with Timeout Source: https://context7.com/programatik29/axum-server/llms.txt Initiates a graceful shutdown of the server, allowing a specified duration for active connections to complete. It also monitors the connection count during the shutdown process. ```rust use axum::{routing::get, Router}; use axum_server::Handle; use std::{net::SocketAddr, time::Duration}; use tokio::time::sleep; #[tokio::main] async fn main() { let app = Router::new().route("/", get(|| async { "Hello, world!" })); let handle = Handle::new(); // Spawn a task to gracefully shutdown server after 10 seconds tokio::spawn(graceful_shutdown(handle.clone())); let addr = SocketAddr::from(([127, 0, 0, 1], 3000)); println!("listening on {}", addr); axum_server::bind(addr) .handle(handle) .serve(app.into_make_service()) .await .unwrap(); println!("server is shut down"); } async fn graceful_shutdown(handle: Handle) { // Wait 10 seconds before initiating shutdown sleep(Duration::from_secs(10)).await; println!("sending graceful shutdown signal"); // Signal graceful shutdown with 30 second timeout // None means wait indefinitely for connections to close handle.graceful_shutdown(Some(Duration::from_secs(30))); // Monitor active connections during shutdown loop { sleep(Duration::from_secs(1)).await; println!("alive connections: {}", handle.connection_count()); } } ``` -------------------------------- ### Server Control Handle API Source: https://context7.com/programatik29/axum-server/llms.txt The Handle provides runtime control over the server including shutdown signaling, graceful shutdown with timeout, and connection counting. It can be cloned and shared across tasks. ```APIDOC ## Handle - Server Control Handle ### Description The Handle provides runtime control over the server including shutdown signaling, graceful shutdown with timeout, and connection counting. It can be cloned and shared across tasks. ### Method N/A (This is a struct with methods) ### Endpoint N/A ### Methods #### `Handle::new()` Creates a new Handle. #### `Handle::clone()` Clones the Handle, allowing it to be shared across tasks. #### `Handle::graceful_shutdown(timeout: Option)` Initiates a graceful shutdown of the server. The `timeout` parameter specifies how long to wait for active connections to close. If `None`, it waits indefinitely. #### `Handle::shutdown()` Immediately shuts down the server, terminating all active connections without waiting. #### `Handle::listening()` Waits for the server to bind and returns the actual listening address. Returns `None` if binding fails. #### `Handle::connection_count()` Returns the current number of active connections being handled by the server. ### Request Example ```rust use axum::Router; use axum_server::Handle; use std::time::Duration; let app = Router::new(); let handle = Handle::new(); // Example of spawning a shutdown task tokio::spawn(async move { tokio::time::sleep(Duration::from_secs(10)).await; handle.graceful_shutdown(Some(Duration::from_secs(30))); }); // Example of binding with a handle // axum_server::bind(addr).handle(handle).serve(app.into_make_service()).await; ``` ### Response N/A (Methods operate on the server state) ### Error Handling - `listening()` returns `None` if binding fails. ``` -------------------------------- ### Customize Connection Handling with NoDelayAcceptor Source: https://context7.com/programatik29/axum-server/llms.txt Use `NoDelayAcceptor` to set TCP_NODELAY on all incoming connections. This is useful for reducing latency in real-time applications. ```rust use axum::{routing::get, Router}; use axum_server::accept::NoDelayAcceptor; use std::net::SocketAddr; #[tokio::main] async fn main() { let app = Router::new().route("/", get(|| async { "Hello, world!" })); let addr = SocketAddr::from(([127, 0, 0, 1], 3000)); axum_server::bind(addr) .acceptor(NoDelayAcceptor::new()) // Set TCP_NODELAY on all connections .serve(app.into_make_service()) .await .unwrap(); } ``` -------------------------------- ### Server::http1_only - HTTP/1 Only Mode Source: https://context7.com/programatik29/axum-server/llms.txt Configures the server to accept only HTTP/1 connections, disabling HTTP/2 protocol negotiation. ```APIDOC ## Server::http1_only - HTTP/1 Only Mode ### Description Configures the server to accept only HTTP/1 connections, disabling HTTP/2 protocol negotiation. ### Method PUT ### Endpoint /api/server/protocol ### Parameters #### Request Body - **protocol** (string) - Required - Set to "http1" to enable HTTP/1 only mode. ### Request Example ```json { "protocol": "http1" } ``` ### Response #### Success Response (200) - **message** (string) - Confirmation that the server is configured for HTTP/1 only. #### Response Example ```json { "message": "Server configured for HTTP/1 only." } ``` ``` -------------------------------- ### RustlsConfig: Hot Reload TLS Certificates Source: https://context7.com/programatik29/axum-server/llms.txt Implement hot-reloading for TLS certificates to update them dynamically without restarting the server. The configuration can be cloned, and reloads will affect all connections using that config. ```rust use axum::{routing::get, Router}; use axum_server::tls_rustls::RustlsConfig; use std::{net::SocketAddr, time::Duration}; use tokio::time::sleep; #[tokio::main] async fn main() { let app = Router::new().route("/", get(|| async { "Hello, world!" })); let config = RustlsConfig::from_pem_file( "examples/self-signed-certs/cert.pem", "examples/self-signed-certs/key.pem", ) .await .unwrap(); // Clone config for use in reload task tokio::spawn(reload_certs(config.clone())); let addr = SocketAddr::from(([127, 0, 0, 1], 3000)); axum_server::bind_rustls(addr, config) .serve(app.into_make_service()) .await .unwrap(); } async fn reload_certs(config: RustlsConfig) { loop { sleep(Duration::from_secs(3600)).await; // Reload every hour println!("Reloading TLS certificates"); // Reload from new certificate files if let Err(e) = config.reload_from_pem_file( "examples/self-signed-certs/cert.pem", "examples/self-signed-certs/key.pem", ).await { eprintln!("Failed to reload certificates: {}", e); } else { println!("TLS certificates reloaded successfully"); } } } ``` -------------------------------- ### HTTP/1 Only Mode Source: https://context7.com/programatik29/axum-server/llms.txt Configures the server to accept only HTTP/1 connections, disabling HTTP/2 protocol negotiation. ```rust use axum::{routing::get, Router}; use axum_server::Server; use std::net::SocketAddr; #[tokio::main] async fn main() { let app = Router::new().route("/", get(|| async { "Hello, world!" })); let addr = SocketAddr::from(([127, 0, 0, 1], 3000)); Server::bind(addr) .http1_only() .serve(app.into_make_service()) .await .unwrap(); } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.