Function from_tcp
Source pub fn from_tcp(listener: TcpListener) -> Server
Expand description
Create a Server
from existing std::net::TcpListener
.
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);
axum_server::from_tcp(listener)
.serve(app.into_make_service())
.await
.unwrap();
}