~repos /rust-embed

#rust#proc-macro#http

git clone https://pyrossh.dev/repos/rust-embed.git
Discussions: https://groups.google.com/g/rust-embed-devs

rust macro which loads files into the rust binary at compile time during release and loads the file from the fs during dev.


Files changed (2) hide show
  1. Cargo.toml +5 -0
  2. tests/mime_guess.rs +35 -0
Cargo.toml CHANGED
@@ -56,6 +56,11 @@ name = "include_exclude"
56
56
  path = "tests/include_exclude.rs"
57
57
  required-features = ["include-exclude"]
58
58
 
59
+ [[test]]
60
+ name = "mime_guess"
61
+ path = "tests/mime_guess.rs"
62
+ required-features = ["mime-guess"]
63
+
59
64
  [dependencies]
60
65
  walkdir = "2.3.1"
61
66
  rust-embed-impl = { version = "6.3.1", path = "impl"}
tests/mime_guess.rs ADDED
@@ -0,0 +1,35 @@
1
+ use rust_embed::{RustEmbed, EmbeddedFile};
2
+
3
+ #[derive(RustEmbed)]
4
+ #[folder = "examples/public/"]
5
+ struct Asset;
6
+
7
+ #[test]
8
+ fn html_mime_is_correct() {
9
+ let html_file: EmbeddedFile = Asset::get("index.html").expect("index.html exists");
10
+ assert_eq!(html_file.metadata.mimetype(), "text/html");
11
+ }
12
+
13
+ #[test]
14
+ fn css_mime_is_correct() {
15
+ let css_file: EmbeddedFile = Asset::get("main.css").expect("main.css exists");
16
+ assert_eq!(css_file.metadata.mimetype(), "text/css");
17
+ }
18
+
19
+ #[test]
20
+ fn js_mime_is_correct() {
21
+ let js_file: EmbeddedFile = Asset::get("main.js").expect("main.js exists");
22
+ assert_eq!(js_file.metadata.mimetype(), "application/javascript");
23
+ }
24
+
25
+ #[test]
26
+ fn jpg_mime_is_correct() {
27
+ let jpg_file: EmbeddedFile = Asset::get("images/flower.jpg").expect("flower.jpg exists");
28
+ assert_eq!(jpg_file.metadata.mimetype(), "image/jpeg");
29
+ }
30
+
31
+ #[test]
32
+ fn png_mime_is_correct() {
33
+ let png_file: EmbeddedFile = Asset::get("images/llama.png").expect("llama.png exists");
34
+ assert_eq!(png_file.metadata.mimetype(), "image/png");
35
+ }