~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. impl/src/lib.rs +2 -2
  2. tests/lib.rs +9 -0
impl/src/lib.rs CHANGED
@@ -15,7 +15,7 @@ fn generate_assets(ident: &syn::Ident, folder_path: String) -> TokenStream2 {
15
15
  use std::fs;
16
16
  use std::path::Path;
17
17
 
18
- let file_path = Path::new(#folder_path).join(file_path);
18
+ let file_path = Path::new(#folder_path).join(file_path.replace("\\", "/"));
19
19
  match fs::read(file_path) {
20
20
  Ok(contents) => Some(std::borrow::Cow::from(contents)),
21
21
  Err(_e) => {
@@ -80,7 +80,7 @@ fn generate_assets(ident: &syn::Ident, folder_path: String) -> TokenStream2 {
80
80
  quote! {
81
81
  impl #ident {
82
82
  pub fn get(file_path: &str) -> Option<std::borrow::Cow<'static, [u8]>> {
83
- match file_path {
83
+ match file_path.replace("\\", "/").as_str() {
84
84
  #(#match_values)*
85
85
  _ => None,
86
86
  }
tests/lib.rs CHANGED
@@ -18,6 +18,15 @@ fn get_works() {
18
18
  }
19
19
  }
20
20
 
21
+ /// Using Windows-style path separators (`\`) is acceptable
22
+ #[test]
23
+ fn get_windows_style() {
24
+ assert!(
25
+ Asset::get("images\\llama.png").is_some(),
26
+ "llama.png should be accessible via \"images\\lama.png\""
27
+ );
28
+ }
29
+
21
30
  #[test]
22
31
  fn iter_works() {
23
32
  let mut num_files = 0;