~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 (1) hide show
  1. utils/src/lib.rs +7 -2
utils/src/lib.rs CHANGED
@@ -87,12 +87,13 @@ pub struct EmbeddedFile {
87
87
  pub struct Metadata {
88
88
  hash: [u8; 32],
89
89
  last_modified: Option<u64>,
90
+ is_dir: bool,
90
91
  }
91
92
 
92
93
  impl Metadata {
93
94
  #[doc(hidden)]
94
- pub fn __rust_embed_new(hash: [u8; 32], last_modified: Option<u64>) -> Self {
95
+ pub fn __rust_embed_new(hash: [u8; 32], last_modified: Option<u64>, is_dir: bool) -> Self {
95
- Self { hash, last_modified }
96
+ Self { hash, last_modified, is_dir }
96
97
  }
97
98
 
98
99
  /// The SHA256 hash of the file
@@ -105,6 +106,9 @@ impl Metadata {
105
106
  pub fn last_modified(&self) -> Option<u64> {
106
107
  self.last_modified
107
108
  }
109
+
110
+ /// Check if an entry is a directory
111
+ pub fn is_dir(&self) -> bool { self.is_dir }
108
112
  }
109
113
 
110
114
  pub fn read_file_from_fs(file_path: &Path) -> io::Result<EmbeddedFile> {
@@ -132,6 +136,7 @@ pub fn read_file_from_fs(file_path: &Path) -> io::Result<EmbeddedFile> {
132
136
  metadata: Metadata {
133
137
  hash,
134
138
  last_modified: source_date_epoch.or(last_modified),
139
+ is_dir: fs::metadata(file_path)?.is_dir(),
135
140
  },
136
141
  })
137
142
  }