diff --git a/bok-macro/src/pkgs.rs b/bok-macro/src/pkgs.rs index f454507..c250d40 100644 --- a/bok-macro/src/pkgs.rs +++ b/bok-macro/src/pkgs.rs @@ -203,10 +203,14 @@ pub(crate) fn deps_build( let pkg_trait = quote::format_ident!("BokDeps{}", ident); + use ::convert_case::{Case, Casing}; let deps = packages .0 .iter() - .map(|x| x.segments.last().unwrap().ident.clone()) + .map(|x| { + let ident = x.segments.last().unwrap().ident.clone(); + quote::format_ident!("{}", ident.to_string().to_case(Case::Snake)) + }) .collect::>(); quote! { diff --git a/bok-macro/src/repos.rs b/bok-macro/src/repos.rs index 7f1a397..4585f1e 100644 --- a/bok-macro/src/repos.rs +++ b/bok-macro/src/repos.rs @@ -192,44 +192,18 @@ pub(crate) fn derive_repository(input: TokenStream) -> TokenStream { .into(); } // holds the list of all package names, snake case - let mut all_pkgs = - Vec::<(String, ::syn::Path)>::with_capacity(items.fields.len()); + let mut all_pkgs = Vec::<::syn::Ident>::with_capacity(items.fields.len()); for it in items.fields.iter() { let Some(id) = &it.ident else { continue }; let id_str = id.to_string(); if id_str.starts_with("_p_") { - let path = { - let ::syn::Type::Path(phantom_path) = &it.ty else { - continue; - }; - let segment = phantom_path.path.segments.last().unwrap(); - let ::syn::PathArguments::AngleBracketed(bracketed) = - &segment.arguments - else { - panic!("derive: phantom without anglebracket?"); - }; - let ::syn::GenericArgument::Type(::syn::Type::Path(t)) = - bracketed.args.first().expect("phantom bracketed, no args") - else { - panic!( - "derive: phantom bracketed, generic not a type path" - ); - }; - t.path.clone() - }; let name = id_str.strip_prefix("_p_").unwrap().to_owned(); - all_pkgs.push((name, path)); + all_pkgs.push(::quote::format_ident!("{}", name)); } } - all_pkgs.sort_by(|a, b| a.0.cmp(&b.0)); + all_pkgs.sort_by(|a, b| a.to_string().cmp(&b.to_string())); let pkgs_num: usize = all_pkgs.len(); - let (pkg_names, pkg_types): (Vec, Vec<::syn::Path>) = - all_pkgs.into_iter().map(|(a, b)| (a, b)).unzip(); - let pkg_ident = pkg_types - .iter() - .map(|p| p.segments.last().unwrap().ident.clone()) - .collect::>(); quote! { impl ::bok::Repository for #name { @@ -241,14 +215,14 @@ pub(crate) fn derive_repository(input: TokenStream) -> TokenStream { } fn pkg_list(&self) -> &[&'static str] { const PKGS : [&'static str; #pkgs_num] = [ - #(#pkg_names), + #(stringify!(#all_pkgs)), * ]; &PKGS } fn get(&self, pkg_name: &str) -> Option<::std::boxed::Box> { match pkg_name { - #(#pkg_names => Some(::std::boxed::Box::new(self.#pkg_ident())),) + #(#all_pkgs => Some(::std::boxed::Box::new(self.#all_pkgs())),) * _ => None, } @@ -505,7 +479,11 @@ pub(crate) fn repo_impl_methods( let pkg_name = { let segment = t_id.segments.iter().last().unwrap(); - &segment.ident + use ::convert_case::{Case, Casing}; + ::quote::format_ident!( + "{}", + segment.ident.to_string().to_case(Case::Snake) + ) }; all_pkgs_types.push(t_id.clone()); if local