More macro!
This commit is contained in:
parent
472d7c923a
commit
5d182997d9
26
src/lib.rs
26
src/lib.rs
|
@ -27,3 +27,29 @@ pub fn manifest_list(dir: proc_macro::TokenStream) -> proc_macro::TokenStream {
|
||||||
|
|
||||||
gen.into()
|
gen.into()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[proc_macro]
|
||||||
|
pub fn mod_manifest_list(dir: proc_macro::TokenStream) -> proc_macro::TokenStream {
|
||||||
|
let dir = dir.to_string();
|
||||||
|
let dir = dir.trim_matches('"');
|
||||||
|
let paths: Vec<String> = fs::read_dir(dir).unwrap().filter_map(|entry| {
|
||||||
|
let path = entry.ok()?.path();
|
||||||
|
if path.is_file() && path.file_name()?.to_str() != Some("mod.rs") {
|
||||||
|
path.file_name()?.to_str().map(|s| s.to_owned().replace(".rs", ""))
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}).collect();
|
||||||
|
|
||||||
|
// Generate the output tokens
|
||||||
|
let paths: Vec<proc_macro2::TokenStream> = paths.iter().map(|path| {
|
||||||
|
let ident = syn::Ident::new(path, proc_macro2::Span::call_site());
|
||||||
|
quote! { mod #ident; }
|
||||||
|
}).collect();
|
||||||
|
|
||||||
|
let gen = quote! {
|
||||||
|
#(#paths)*
|
||||||
|
};
|
||||||
|
|
||||||
|
gen.into()
|
||||||
|
}
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
use infra_rs::manifest_list;
|
use infra_rs::{mod_manifest_list, manifest_list};
|
||||||
|
|
||||||
use crate::infra_rs::ResourceList;
|
use crate::infra_rs::ResourceList;
|
||||||
|
|
||||||
mod vaultwarden;
|
mod_manifest_list!("./src/manifests");
|
||||||
|
|
||||||
pub fn render() -> ResourceList {
|
pub fn render() -> ResourceList {
|
||||||
let resources = manifest_list!("./src/manifests");
|
let resources = manifest_list!("./src/manifests");
|
||||||
|
|
Loading…
Reference in a new issue