~repos /rust-embed
git clone https://pyrossh.dev/repos/rust-embed.git
rust macro which loads files into the rust binary at compile time during release and loads the file from the fs during dev.
86d7f802
—
Jasper van Herpt 3 years ago
Extend property to macro
- impl/src/lib.rs +4 -2
impl/src/lib.rs
CHANGED
|
@@ -6,7 +6,7 @@ extern crate proc_macro;
|
|
|
6
6
|
|
|
7
7
|
use proc_macro::TokenStream;
|
|
8
8
|
use proc_macro2::TokenStream as TokenStream2;
|
|
9
|
-
use std::{env, path::Path};
|
|
9
|
+
use std::{env, fs, path::Path};
|
|
10
10
|
use syn::{Data, DeriveInput, Fields, Lit, Meta, MetaNameValue};
|
|
11
11
|
|
|
12
12
|
fn embedded(ident: &syn::Ident, folder_path: String, prefix: Option<&str>, includes: &[String], excludes: &[String]) -> TokenStream2 {
|
|
@@ -170,6 +170,7 @@ fn generate_assets(ident: &syn::Ident, folder_path: String, prefix: Option<Strin
|
|
|
170
170
|
fn embed_file(rel_path: &str, full_canonical_path: &str) -> TokenStream2 {
|
|
171
171
|
let file = rust_embed_utils::read_file_from_fs(Path::new(full_canonical_path)).expect("File should be readable");
|
|
172
172
|
let hash = file.metadata.sha256_hash();
|
|
173
|
+
let is_dir = file.metadata.is_dir();
|
|
173
174
|
let last_modified = match file.metadata.last_modified() {
|
|
174
175
|
Some(last_modified) => quote! { Some(#last_modified) },
|
|
175
176
|
None => quote! { None },
|
|
@@ -192,7 +193,8 @@ fn embed_file(rel_path: &str, full_canonical_path: &str) -> TokenStream2 {
|
|
|
192
193
|
|
|
193
194
|
Some(rust_embed::EmbeddedFile {
|
|
194
195
|
data: std::borrow::Cow::from(bytes),
|
|
195
|
-
metadata: rust_embed::Metadata::__rust_embed_new([#(#hash),*], #last_modified)
|
|
196
|
+
metadata: rust_embed::Metadata::__rust_embed_new([#(#hash),*], #last_modified),
|
|
197
|
+
is_dir: #is_dir
|
|
196
198
|
})
|
|
197
199
|
}
|
|
198
200
|
}
|