Skip to main content

serve

Function serve 

Source
pub async fn serve<F>(app: App, addr: SocketAddr, shutdown: F) -> Result<()>
where F: Future<Output = ()> + Send + 'static,
Expand description

Serve app on addr until shutdown resolves (graceful drain).

Uses HTTP/1.1 (hyper::server::conn::http1::Builder). The plan referenced auto::Builder but that type’s serve_connection returns a Connection<'_, …> that borrows the builder, which cannot be moved into a tokio::spawn closure. Using http1::Builder directly returns an owned Connection<I, S> that is 'static, compiles correctly, and still satisfies the HTTP/1.1-only requirement of Plan 1.

Prefer App::start / App::start_with_shutdown unless you need to control the bind address and shutdown future yourself.

use churust_core::{Churust, Call, engine};
let app = Churust::server()
    .routing(|r| { r.get("/", |_c: Call| async { "hi" }); })
    .build();
let addr = "127.0.0.1:8080".parse().unwrap();
// Serve until Ctrl-C.
engine::serve(app, addr, async { let _ = tokio::signal::ctrl_c().await; }).await?;