Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

example in https://actix.rs/docs/request/ has error #594

Closed
aohan237 opened this issue Nov 20, 2018 · 2 comments
Closed

example in https://actix.rs/docs/request/ has error #594

aohan237 opened this issue Nov 20, 2018 · 2 comments
Labels
C-docs Category: docs

Comments

@aohan237
Copy link

aohan237 commented Nov 20, 2018

error[E0277]: the size for values of type [u8] cannot be known at compilation time

extern crate serde_json;
use futures::{Future, Stream};

#[derive(Serialize, Deserialize)]
struct MyObj {name: String, number: i32}

fn index(req: &HttpRequest) -> Box<Future<Item=HttpResponse, Error=Error>> {
   // `concat2` will asynchronously read each chunk of the request body and
   // return a single, concatenated, chunk
   req.concat2()
      // `Future::from_err` acts like `?` in that it coerces the error type from
      // the future into the final error type
      .from_err()
      // `Future::and_then` can be used to merge an asynchronous workflow with a
      // synchronous workflow
      .and_then(|body| {
          let obj = serde_json::from_slice::<MyObj>(&body)?;
          Ok(HttpResponse::Ok().json(obj))
      })
      .responder()
}
@DoumanAsh
Copy link
Contributor

I'm not sure where exactly is error, I assume it is at line with from_slice but if it is not difficult you can make PR to correct it here

@fafhrd91 fafhrd91 added the C-docs Category: docs label Apr 1, 2019
@fafhrd91
Copy link
Member

Outdated

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-docs Category: docs
Projects
None yet
Development

No branches or pull requests

3 participants