I am getting frustrated with Rust’s return type errors. Even though I am writing correct code, since it is not complete, it is interpreted as a syntax mistake, leading to numerous errors. Below is an example of an error I encounter when writing a web server using tokio.
async fn main() {
HttpServer::new(|| {
App::new()
.route("/", web::get().to(greet()))
.route("/{name}", web::get().to(greet))
})
}
Errors appear from the line HttpServer::new(|| {
and continue until .route("/{name}", web::get().to(greet))
. The errors disappear after adding .bind("127.0.0.1:8000")
at the end.
I can tolerate one or two lines of errors, but multiple lines of errors are quite frustrating. However, turning off the errors would be problematic as I wouldn’t be notified of actual mistakes. Is there a way to reduce the errors while writing, without turning them off entirely? Even if there is no solution, any advice to mitigate the frustration would be appreciated.
I don’t know how to solve it.