Actix-web: Needs `actix_rt` dependency to start

Created on 6 Feb 2020  路  7Comments  路  Source: actix/actix-web

The crate actix_rt is already a dependency and thus should be available for use.

use actix_web::{get, web, App, HttpServer, Responder};

#[get("/{id}/{name}/index.html")]
async fn index(info: web::Path<(u32, String)>) -> impl Responder {
    format!("Hello {}! id:{}", info.1, info.0)
}

#[actix_rt::main]
async fn main() -> std::io::Result<()> {
    HttpServer::new(|| App::new().service(index))
        .bind("127.0.0.1:4444")?
        .run()
        .await
}

When I try to execute the simplest example from the docs I get an error.

error[E0433]: failed to resolve: use of undeclared type or module `actix_rt`
  --> src/main.rs:19:3
   |
19 | #[actix_rt::main]
   |   ^^^^^^^^ use of undeclared type or module `actix_rt`

error[E0433]: failed to resolve: use of undeclared type or module `env_logger`
  --> src/main.rs:22:5
   |
22 |     env_logger::init();
   |     ^^^^^^^^^^ use of undeclared type or module `env_logger`

error[E0277]: `main` has invalid return type `impl std::future::Future`
  --> src/main.rs:20:20
   |
20 | async fn main() -> std::io::Result<()> {
   |                    ^^^^^^^^^^^^^^^^^^^ `main` can only return types that implement `std::process::Termination`
   |
   = help: consider using `()`, or a `Result`

error: aborting due to 3 previous errors

The error disappears by adding actix_rt dependency in the Cargo.toml. If this is the expected behaviour then the docs needs to be updated.

C-docs

Most helpful comment

Largely agree with @elliotekj but it might be worth updating https://actix.rs/docs/installation/ to mention the dependency or re-evaluating the value of that page.

All 7 comments

actix_rt is a dependency but it isn't re-exported. Requiring actix_rt along with actix_web seems to be expected behavior as it's documented in the readme and on the website (though it's missing on docs.rs).

Largely agree with @elliotekj but it might be worth updating https://actix.rs/docs/installation/ to mention the dependency or re-evaluating the value of that page.

/docs/installation isn't a guide I'd probably write if it didn't already exist, but as it has already been written, I'd vote to keep it. Though what it covers is both fairly basic and non-specific to actix-web, a web framework is a plausible way to start exploring and learning a new language and some may find it helpful. I think it just needs updating as @robjtede pointed out.

my real issue with it is that most of the content is duplicated from the getting started page (which, in my opinion, would make a better starting point for the primary button on the home page, currently labelled "Install")

which, in my opinion, would make a better starting point for the primary button on the home page, currently labelled "Install"

Agreed, though it should probably then be re-labelled to "Get Started".

yes, that as well

As there hasn't been any more feedback on this one way or the other, I've started a revamp of the getting started docs that will allow the deletion of the installation guide. In the meantime, I think this issue can be closed once #1343 has been merged.

Was this page helpful?
0 / 5 - 0 ratings