~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.
9c530ba1
—
pyros2097 5 years ago
Merge branch 'master' of github.com:pyros2097/rust-embed
- impl/src/lib.rs +3 -11
impl/src/lib.rs
CHANGED
|
@@ -12,20 +12,12 @@ fn generate_assets(ident: &syn::Ident, folder_path: String) -> TokenStream2 {
|
|
|
12
12
|
quote! {
|
|
13
13
|
impl #ident {
|
|
14
14
|
pub fn get(file_path: &str) -> Option<std::borrow::Cow<'static, [u8]>> {
|
|
15
|
-
use std::fs
|
|
15
|
+
use std::fs;
|
|
16
|
-
use std::io::Read;
|
|
17
16
|
use std::path::Path;
|
|
18
17
|
|
|
19
18
|
let file_path = Path::new(#folder_path).join(file_path);
|
|
20
|
-
let mut file = match File::open(file_path) {
|
|
21
|
-
Ok(mut file) => file,
|
|
22
|
-
Err(_e) => {
|
|
23
|
-
return None
|
|
24
|
-
}
|
|
25
|
-
};
|
|
26
|
-
let mut data: Vec<u8> = Vec::new();
|
|
27
|
-
match
|
|
19
|
+
match fs::read(file_path) {
|
|
28
|
-
Ok(
|
|
20
|
+
Ok(contents) => Some(std::borrow::Cow::from(contents)),
|
|
29
21
|
Err(_e) => {
|
|
30
22
|
return None
|
|
31
23
|
}
|