Skip to content

Instantly share code, notes, and snippets.

@saidaspen
Created September 18, 2020 21:06
Show Gist options
  • Save saidaspen/62eead1aed4ddf618d14a09bead6876f to your computer and use it in GitHub Desktop.
Save saidaspen/62eead1aed4ddf618d14a09bead6876f to your computer and use it in GitHub Desktop.
Type annotation?
#[post("/new")]
async fn new(req_body: String) -> impl Responder {
match serde_json::from_str(req_body.as_str()) {
Err(why) => HttpResponse::BadRequest().body(
json!({
"err": "Unable to parse input as request json",
})
.to_string(),
),
Ok(t) => HttpResponse::Ok().body(format!("{:?}", t)),
}
}
@saidaspen
Copy link
Author

saidaspen commented Sep 18, 2020

Error:

error[E0282]: type annotations needed
  --> src/main.rs:30:42
   |
30 |         Ok(t) => HttpResponse::Ok().body(t.to_string()),
   |                                          ^ cannot infer type
   |
   = note: type must be known at this point

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment