actix-web icon indicating copy to clipboard operation
actix-web copied to clipboard

Build error with AWC 3.0.1 in client::h1proto

Open koalabi opened this issue 2 years ago • 1 comments

When trying to build a sample application from a book's source code, I get a build error in h1proto for which the diagnostic is correct (no "feed" mathod in Pin) but I see no direct alternative nor any mention of breaking change in AWC history. Regressing to AWC 3.0.0 doesn't provide any relief. The book code is being migrated from a previous version of actix_web, so having to use AWC is new but the problem is not with the application code but with the AWC code itself

(excerpt from cargo check output):

    Checking awc v3.0.1
error[E0599]: no method named `feed` found for struct `Pin<&mut Framed<H1Connection<Io>, ClientCodec>>` in the current scope
   --> /home/alain/.cargo/registry/src/github.com-1ecc6299db9ec823/awc-3.0.1/src/client/h1proto.rs:100:20
    |
100 |         pin_framed.feed((head, body.size()).into()).await?;
    |                    ^^^^ method not found in `Pin<&mut Framed<H1Connection<Io>, ClientCodec>>`

For more information about this error, try `rustc --explain E0599`.

Expected Behavior

Normal compilation (as it is pristine crate code and a dependency of the app code) Indeed, "feed" seems to be no method (anymore) of Pin ...

Current Behavior

Compilation fails with message above

Possible Solution

The rest of the book so far has been updated to the last Actix version; so, using a previous version is no option and wouldn't make sense.

Steps to Reproduce (for bugs)

Just use AWC Client as in the following application function

async fn handle_get_tutors(tmpl: web::Data<tera::Tera>) -> Result<HttpResponse, Error> {
    let client = Client::new(); // Client::default();

    // Create request builder and send request

    let response = client
        .get("http://localhost:3000/tutors/")
        .send() // <- Send request
        .await
        .unwrap()
        .body()
        .await
        .unwrap();

    let str_list = std::str::from_utf8(&response.as_ref()).unwrap();
    let tutor_list: Vec<Tutor> = serde_json::from_str(str_list).unwrap();
    let mut ctx = tera::Context::new();

    ctx.insert("tutors", &tutor_list);
    let s = tmpl
        .render("list.html", &ctx)
        .map_err(|_| error::ErrorInternalServerError("Template error"))?;

    Ok(HttpResponse::Ok().content_type("text/html").body(s))
}

Context

Updating book source code from actix_web 3.3 to 4.0.1. App used actix_web::client::Client; which has now disappeared and, according to StackOverflow, awc has now to be used directly.

Your Environment

  • OS: Linux Ubuntu 20.04 LTS workstation
  • Rust Version rustc 1.59.0 (9d1b2106e 2022-02-23)
  • Actix Web Version: 4.2.1

koalabi avatar Sep 14 '22 05:09 koalabi

Not able to reproduce: https://www.rustexplorer.com/b/eo7ndv

Are you compiling with custom crate features?

robjtede avatar Sep 14 '22 17:09 robjtede