Function hyper_serve::from_tcp

source ยท
pub fn from_tcp(listener: TcpListener) -> Server
Expand description

Create a Server from existing std::net::TcpListener.

Examples found in repository?
examples/from_std_listener.rs (line 15)
9
10
11
12
13
14
15
16
17
18
19
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);
    hyper_serve::from_tcp(listener)
        .serve(app.into_make_service())
        .await
        .unwrap();
}