Actix-web 1.0: Checkboxes, extractors and futures

I’m trying to implement a small voting system when a logged user can vote for multiple choices/candidates.

It seems like using a Form with checkboxes is a difficult problem, so I now try to parse the body/payload.

  • I got mismatch type between the two branches of if let Some(), Future != AndThen;
  • I wanted to do an extractor for logged user, but I can’t construct Identity myself because it’s private;
  • If I remove the .wait() I can’t compile;
pub fn vote(
    id: Identity,
    payload: web::Payload,
) -> impl Future<Item = HttpResponse, Error = Error> {
    if let Some(email) = id.identity() {
        let body = payload
            .and_then(|body| future::ok(body))
            .wait() // This is blocking the request
        let vec = serde_urlencoded::from_bytes::<Vec<(String, i32)>>(&body).ok();
        println!("{:?}", vec); // Let's build the Vote { choice: <Vec<i32>> } later
                .header("location", "/#dankon")
    } else {
        return future::ok(HttpResponse::Found().header("location", "/").finish());

Is there a way to get the body in a more simple way?
How to implement a logged user extractor (FromRequest) in Actix-web 1.0?

Do you have any insights on this @fafhrd91 ?

try this one