1
0
mirror of https://github.com/fafhrd91/actix-net synced 2024-11-24 02:21:07 +01:00
actix-net/actix-rt/examples/hyper.rs

30 lines
803 B
Rust
Raw Permalink Normal View History

2022-04-10 03:48:53 +02:00
use std::{convert::Infallible, net::SocketAddr};
use hyper::{
service::{make_service_fn, service_fn},
Body, Request, Response, Server,
};
2021-02-03 11:25:31 +01:00
async fn handle(_req: Request<Body>) -> Result<Response<Body>, Infallible> {
Ok(Response::new(Body::from("Hello World")))
}
fn main() {
actix_rt::System::with_tokio_rt(|| {
tokio::runtime::Builder::new_multi_thread()
.enable_all()
.build()
.unwrap()
})
.block_on(async {
let make_service =
make_service_fn(|_conn| async { Ok::<_, Infallible>(service_fn(handle)) });
2023-07-17 04:05:39 +02:00
let server = Server::bind(&SocketAddr::from(([127, 0, 0, 1], 3000))).serve(make_service);
2021-02-03 11:25:31 +01:00
2022-01-28 22:46:17 +01:00
if let Err(err) = server.await {
eprintln!("server error: {}", err);
2021-02-03 11:25:31 +01:00
}
})
}