[F] Fix main execution
This commit is contained in:
+7
-2
@@ -22,16 +22,19 @@ extern crate pretty_env_logger;
|
|||||||
#[macro_use] extern crate log;
|
#[macro_use] extern crate log;
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() {
|
async fn main() -> Result<()> {
|
||||||
|
pretty_env_logger::init();
|
||||||
|
|
||||||
let cwd = env::current_dir().unwrap();
|
let cwd = env::current_dir().unwrap();
|
||||||
let addr = SocketAddr::from(([127, 0, 0, 1], 3029));
|
let addr = SocketAddr::from(([127, 0, 0, 1], 3029));
|
||||||
info!("Serving {} started on http://127.0.0.1:3029", cwd.display());
|
info!("Serving {} started on http://127.0.0.1:3029", cwd.display());
|
||||||
|
let app: &MyApp = Box::leak(Box::new(MyApp::new(&cwd).unwrap())) as &'static _;
|
||||||
|
|
||||||
// A `Service` is needed for every connection, so this
|
// A `Service` is needed for every connection, so this
|
||||||
// creates one from our `hello_world` function.
|
// creates one from our `hello_world` function.
|
||||||
let make_svc = make_service_fn(|_conn| async {
|
let make_svc = make_service_fn(|_conn| async {
|
||||||
// service_fn converts our function into a `Service`
|
// service_fn converts our function into a `Service`
|
||||||
Ok::<_, Infallible>(service_fn(hello_world))
|
Ok::<_, Infallible>(service_fn(|x| app.hello_world(x)))
|
||||||
});
|
});
|
||||||
|
|
||||||
let server = Server::bind(&addr).serve(make_svc);
|
let server = Server::bind(&addr).serve(make_svc);
|
||||||
@@ -40,6 +43,8 @@ async fn main() {
|
|||||||
if let Err(e) = server.await {
|
if let Err(e) = server.await {
|
||||||
eprintln!("server error: {}", e);
|
eprintln!("server error: {}", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Serialize, Deserialize)]
|
||||||
|
|||||||
Reference in New Issue
Block a user