1
Fork 0
mirror of https://github.com/RGBCube/embd-rs synced 2025-07-27 13:37:44 +00:00
This commit is contained in:
RGBCube 2024-01-02 17:18:18 +03:00
parent c031e19e7f
commit 58a1fa2182
No known key found for this signature in database
3 changed files with 10 additions and 6 deletions

1
Cargo.lock generated
View file

@ -13,6 +13,7 @@ dependencies = [
name = "embed_macros" name = "embed_macros"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"proc-macro2",
"quote", "quote",
"syn", "syn",
] ]

View file

@ -13,5 +13,6 @@ edition = "2021"
proc_macro = true proc_macro = true
[dependencies] [dependencies]
proc-macro2 = "1"
quote = "1" quote = "1"
syn = "2" syn = "2"

View file

@ -3,7 +3,8 @@ use std::{
path::PathBuf, path::PathBuf,
}; };
use proc_macro::TokenStream; use proc_macro as pm1;
use proc_macro2::TokenStream;
use quote::quote; use quote::quote;
use syn::{ use syn::{
parse_macro_input, parse_macro_input,
@ -11,7 +12,7 @@ use syn::{
}; };
#[proc_macro] #[proc_macro]
pub fn __include_dir(tokens: TokenStream) -> TokenStream { pub fn __include_dir(tokens: pm1::TokenStream) -> pm1::TokenStream {
let path = parse_macro_input!(tokens as LitStr).value(); let path = parse_macro_input!(tokens as LitStr).value();
let path = PathBuf::from(path) let path = PathBuf::from(path)
@ -27,12 +28,13 @@ pub fn __include_dir(tokens: TokenStream) -> TokenStream {
vec![#(#children),*] vec![#(#children),*]
}; };
TokenStream::from(quote! { (quote! {
::embed::Dir { ::embed::Dir {
children: #children_tokens, children: #children_tokens,
path: ::std::path::PathBuf::from(#path_str), path: ::std::path::PathBuf::from(#path_str),
} }
}) })
.into()
} }
fn read_dir(path: &PathBuf) -> Vec<TokenStream> { fn read_dir(path: &PathBuf) -> Vec<TokenStream> {
@ -50,7 +52,7 @@ fn read_dir(path: &PathBuf) -> Vec<TokenStream> {
.to_str() .to_str()
.expect("Failed to get the string representation of PathBuf"); .expect("Failed to get the string representation of PathBuf");
let filetype = fs::metadata(path) let filetype = fs::metadata(&path)
.expect("Failed to get file metadata") .expect("Failed to get file metadata")
.file_type(); .file_type();