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

The mime-guess feature doesn't work #209

Closed
vicanso opened this issue Mar 24, 2023 · 4 comments
Closed

The mime-guess feature doesn't work #209

vicanso opened this issue Mar 24, 2023 · 4 comments

Comments

@vicanso
Copy link

vicanso commented Mar 24, 2023

When I enable the mime-guess feature like this:

rust-embed = { version = "6.6.0", features = ["compression", "mime-guess"] }

I can't get the mimetype from metadata, and the build error is:

24 |         println!("{:?}", file.metadata.mimetype());
   |                                        ^^^^^^^^ method not found in `Metadata`
@pyrossh
Copy link
Owner

pyrossh commented Mar 24, 2023

Hmm... we do have test cases that test this feature out though.
https://github.com/pyrossh/rust-embed/blob/master/tests/mime_guess.rs#L28
And this is running in our pipeline,
cargo test --test mime_guess --features "mime-guess"
What could be going wrong?

@BBaoVanC
Copy link
Contributor

I'm confused too, it works in my app (https://github.com/BBaoVanC/bobashare, in bobashare-web/src/static_routes.rs), but I don't see Metadata::mimetype listed at all in the rustdoc (although maybe it can't tell it exists), and this simple code fails:

use rust_embed::RustEmbed;

#[derive(RustEmbed)]
#[folder = "static/"]
struct Asset;

fn main() {
    Asset::get("abc").map(|f| f.metadata.mimetype());
}

Not sure what is going on and how it's working fine for me

@vicanso
Copy link
Author

vicanso commented Mar 25, 2023

@pyrossh I find that if I add this dependency, it works.

rust-embed-utils = { version = "7.5.0", features = ["mime-guess"] }

@pyrossh
Copy link
Owner

pyrossh commented Mar 25, 2023

@vicanso thanks, that was it. The mime-guess feature didn't include the utils crate feature hence the issue. https://github.com/pyrossh/rust-embed/blob/master/Cargo.toml#L87. I've added it now and released v6.6.1 and it works.

Here is a simple example,

use rust_embed::RustEmbed;

#[derive(RustEmbed)]
#[folder = "static/"]
struct Asset;

fn main() {
    println!("{:?}", Asset::get("main.js").unwrap().metadata.mimetype())
}

@pyrossh pyrossh closed this as completed Mar 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants