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

Issue:
Rocket example with Rocket 0.5.0-rc.1 & Rust 1.56.1
Hi,

The Rocket example does not compile with Rocket 0.5.0-rc.1 & Rust 1.56.1

sized_body complains the 'size' parameter is missing
The syntax "fn index<'r>() -> response::Result<'r>" is a no go, compiler complains about it non implementing some black magic thing with 2 lifetimes and if you add the missing lifetime then it complains there are too many lifetimes.
I'm new to Rust so it was way above my level.

Maybe add a comment static which version of Rust/Rocket this will compile against?

As for Rocket 0.5.0-rc.1 & Rust 1.56.1, here is what I've done to make it work:
- provide d.data.len() to the size parameter of sized_body
- create a struct to hold everything used by the routes of the example; EmbeddedFile, PathBuf & ContentType
- implemented a Responder on that struct follwing instructions on https://api.rocket.rs/v0.5-rc/rocket/response/trait.Responder.html#example  : it contains essentially the code which is in the routes of the example. 
- use that implementation in the routes

I'm attaching the code to this issue. As I said, I'm new to Rust so I'm really not sure I did it The Right Way, hence the reason why I'm not submitting a PR right away
[rocket_0.5.0-rc.1.txt](https://github.com/pyros2097/rust-embed/files/7599133/rocket_0.5.0-rc.1.txt)


Discussion / hints:
Don't worry about submitting a PR too early. It's easier to collaborate and see the changes in a PR than in a text file. If you really want, you can even open the PR in draft.

Our Cargo.toml file shows the version of Rocket we compiled against:
https://github.com/pyros2097/rust-embed/blob/34299eb1bc41da92fe5d474036d49b8f2c5b3c00/Cargo.toml#L60

Feel free to open a PR and we can add comments.
I will note though that this would be a simpler implementation (feel free to open a PR with this):
```rust
#[macro_use]
extern crate rocket;

use rocket::http::ContentType;
use rocket::response::content::Html;
use rust_embed::RustEmbed;

use std::borrow::Cow;
use std::ffi::OsStr;
use std::path::PathBuf;

#[derive(RustEmbed)]
#[folder = "examples/public/"]
struct Asset;

#[get("/")]
fn index() -> Option<Html<Cow<'static, [u8]>>> {
  let asset = Asset::get("index.html")?;
  Some(Html(asset.data))
}

#[get("/dist/<file..>")]
fn dist(file: PathBuf) -> Option<(ContentType, Cow<'static, [u8]>)> {
  let filename = file.display().to_string();
  let asset = Asset::get(&filename)?;
  let content_type = file
    .extension()
    .and_then(OsStr::to_str)
    .and_then(ContentType::from_extension)
    .unwrap_or(ContentType::Bytes);
  
  Some((content_type, asset.data))
}

#[rocket::launch]
fn rocket() -> _ {
  rocket::build().mount("/", routes![index, dist])
}
```
No problem, I've adapted to my own project and it works great!
Not sure on how you want me to contribute this though: I mean if you want to keep both examples (in 0.4 & 0.5) than I'm not sure how to impact Cargo.toml
In the PR I would submit this with changes to Cargo.toml to use rocket 0.5 (with the added benefit that it does not need nightly anymore): would that be OK for you?

Yeah, if you're still interested in opening a PR, it would involve bumping the rocket version and replacing the example with the one from this issue. However now that I think of it, there are also some more CI changes needed related to nightly, so I'd be happy to make the changes myself too. Up to you though!
I'm not sure what those CI changes would be, so maybe its best that you do the changes yourself I'd say.
Thanks again for your help!

Fix patch:
diff --git a/Cargo.toml b/Cargo.toml
index b7d4ee5..d3a66d7 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -57,7 +57,7 @@ mime_guess = { version = "2", optional = true }
 hex = { version = "0.4.3", optional = true }
 tokio = { version = "1.0", optional = true, features = ["macros", "rt-multi-thread"] }
 warp = { version = "0.3", default-features = false, optional = true }
-rocket = { version = "0.4.5", default-features = false, optional = true }
+rocket = { version = "0.5.0-rc.1", default-features = false, optional = true }
 axum = { version = "0.4", default-features = false, features = ["http1"], optional = true  }
 poem = { version = "1.0.8", default-features = false, optional = true  }
 
@@ -69,7 +69,6 @@ debug-embed = ["rust-embed-impl/debug-embed", "rust-embed-utils/debug-embed"]
 interpolate-folder-path = ["rust-embed-impl/interpolate-folder-path"]
 compression = ["rust-embed-impl/compression", "include-flate"]
 include-exclude = ["rust-embed-impl/include-exclude", "rust-embed-utils/include-exclude"]
-nightly = ["rocket"]
 actix = ["actix-web", "mime_guess"]
 warp-ex = ["warp", "tokio", "mime_guess"]
 axum-ex = ["axum", "tokio", "mime_guess"]
diff --git a/examples/rocket.rs b/examples/rocket.rs
index 4aa6169..7f8145c 100644
--- a/examples/rocket.rs
+++ b/examples/rocket.rs
@@ -1,13 +1,12 @@
-#![feature(decl_macro, proc_macro_hygiene)]
 #[macro_use]
 extern crate rocket;
 
-use rocket::http::{ContentType, Status};
-use rocket::response;
+use rocket::http::ContentType;
+use rocket::response::content::Html;
 use rust_embed::RustEmbed;
 
+use std::borrow::Cow;
 use std::ffi::OsStr;
-use std::io::Cursor;
 use std::path::PathBuf;
 
 #[derive(RustEmbed)]
@@ -15,30 +14,25 @@ use std::path::PathBuf;
 struct Asset;
 
 #[get("/")]
-fn index<'r>() -> response::Result<'r> {
-  Asset::get("index.html").map_or_else(
-    || Err(Status::NotFound),
-    |d| response::Response::build().header(ContentType::HTML).sized_body(Cursor::new(d.data)).ok(),
-  )
+fn index() -> Option<Html<Cow<'static, [u8]>>> {
+  let asset = Asset::get("index.html")?;
+  Some(Html(asset.data))
 }
 
 #[get("/dist/<file..>")]
-fn dist<'r>(file: PathBuf) -> response::Result<'r> {
+fn dist(file: PathBuf) -> Option<(ContentType, Cow<'static, [u8]>)> {
   let filename = file.display().to_string();
-  Asset::get(&filename).map_or_else(
-    || Err(Status::NotFound),
-    |d| {
-      let ext = file
-        .as_path()
-        .extension()
-        .and_then(OsStr::to_str)
-        .ok_or_else(|| Status::new(400, "Could not get file extension"))?;
-      let content_type = ContentType::from_extension(ext).ok_or_else(|| Status::new(400, "Could not get file content type"))?;
-      response::Response::build().header(content_type).sized_body(Cursor::new(d.data)).ok()
-    },
-  )
+  let asset = Asset::get(&filename)?;
+  let content_type = file
+    .extension()
+    .and_then(OsStr::to_str)
+    .and_then(ContentType::from_extension)
+    .unwrap_or(ContentType::Bytes);
+
+  Some((content_type, asset.data))
 }
 
-fn main() {
-  rocket::ignite().mount("/", routes![index, dist]).launch();
+#[rocket::launch]
+fn rocket() -> _ {
+  rocket::build().mount("/", routes![index, dist])
 }
diff --git a/readme.md b/readme.md
index 06ab5cf..6356b61 100644
--- a/readme.md
+++ b/readme.md
@@ -151,9 +151,9 @@ Note: To run the `actix-web` example:
 
 `cargo run --example actix --features actix`
 
-Note: To run the `rocket` example, add the `nightly` feature flag and run on a nightly build:
+Note: To run the `rocket` example:
 
-`cargo +nightly run --example rocket --features nightly`
+`cargo run --example rocket --features rocket`
 
 Note: To run the `warp` example:
 


Test patch:
diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
index c32b5fb..5177d52 100644
--- a/.github/workflows/test.yml
+++ b/.github/workflows/test.yml
@@ -36,11 +36,13 @@ jobs:
           cargo test --test interpolated_path --features "interpolate-folder-path"
           cargo test --test interpolated_path --features "interpolate-folder-path" --release
           cargo build --example basic
+          cargo build --example rocket --features rocket
           cargo build --example actix --features actix
           cargo build --example axum --features axum-ex
           cargo build --example warp --features warp-ex
           cargo test --test lib --release
           cargo build --example basic --release
+          cargo build --example rocket --features rocket --release
           cargo build --example actix --features actix --release
           cargo build --example axum --features axum-ex --release
           cargo build --example warp --features warp-ex --release