Repository: pyrossh/rust-embed (language: rust)

Issue:
unresolved import `actix_web::body::Body`
https://github.com/pyrossh/rust-embed/blob/master/examples/actix.rs

actix-web = "4.0.0"
actix-http = "3.0.4"

error[E0432]: unresolved import `actix_web::body::Body`
 --> src/controller/index.rs:6:5
  |
6 | use actix_web::body::Body;
  |     ^^^^^^^^^^^^^^^^^^^^^ no `Body` in `body`

Could you please provide an example of `actix-web = "4.0.0"`?





Discussion / hints:

Fix patch:
diff --git a/Cargo.toml b/Cargo.toml
index 37c9f7d..6554c8c 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -52,7 +52,7 @@ rust-embed-impl = { version = "6.2.0", path = "impl"}
 rust-embed-utils = { version = "7.2.0", path = "utils"}
 
 include-flate = { version = "0.1", optional = true, features = ["stable"] }
-actix-web = { version = "3", default-features = false, optional = true }
+actix-web = { version = "4", optional = true }
 mime_guess = { version = "2", optional = true }
 hex = { version = "0.4.3", optional = true }
 tokio = { version = "1.0", optional = true, features = ["macros", "rt-multi-thread"] }
diff --git a/examples/actix.rs b/examples/actix.rs
index 047448b..fc24214 100644
--- a/examples/actix.rs
+++ b/examples/actix.rs
@@ -1,43 +1,31 @@
-use actix_web::body::Body;
-use actix_web::{web, App, HttpResponse, HttpServer};
+use actix_web::{web, App, HttpResponse, HttpServer, Responder};
 use mime_guess::from_path;
 use rust_embed::RustEmbed;
 
-use std::borrow::Cow;
-
 #[derive(RustEmbed)]
 #[folder = "examples/public/"]
 struct Asset;
 
 fn handle_embedded_file(path: &str) -> HttpResponse {
   match Asset::get(path) {
-    Some(content) => {
-      let body: Body = match content.data {
-        Cow::Borrowed(bytes) => bytes.into(),
-        Cow::Owned(bytes) => bytes.into(),
-      };
-      HttpResponse::Ok().content_type(from_path(path).first_or_octet_stream().as_ref()).body(body)
-    }
+    Some(content) => HttpResponse::Ok()
+      .content_type(from_path(path).first_or_octet_stream().as_ref())
+      .body(content.data.into_owned()),
     None => HttpResponse::NotFound().body("404 Not Found"),
   }
 }
 
-fn index() -> HttpResponse {
+#[actix_web::get("/")]
+async fn index() -> impl Responder {
   handle_embedded_file("index.html")
 }
 
-fn dist(path: web::Path<String>) -> HttpResponse {
-  handle_embedded_file(&path.0)
+#[actix_web::get("/dist/{_:.*}")]
+async fn dist(path: web::Path<String>) -> impl Responder {
+  handle_embedded_file(path.as_str())
 }
 
 #[actix_web::main]
 async fn main() -> std::io::Result<()> {
-  HttpServer::new(|| {
-    App::new()
-      .service(web::resource("/").route(web::get().to(index)))
-      .service(web::resource("/dist/{_:.*}").route(web::get().to(dist)))
-  })
-  .bind("127.0.0.1:8000")?
-  .run()
-  .await
+  HttpServer::new(|| App::new().service(index).service(dist)).bind("127.0.0.1:8000")?.run().await
 }


Test patch: