Package names should ne snake case
Signed-off-by: Luca Fulchir <luca.fulchir@runesauth.com>
This commit is contained in:
parent
bf8f6721a4
commit
34a1771695
@ -203,10 +203,14 @@ pub(crate) fn deps_build(
|
|||||||
|
|
||||||
let pkg_trait = quote::format_ident!("BokDeps{}", ident);
|
let pkg_trait = quote::format_ident!("BokDeps{}", ident);
|
||||||
|
|
||||||
|
use ::convert_case::{Case, Casing};
|
||||||
let deps = packages
|
let deps = packages
|
||||||
.0
|
.0
|
||||||
.iter()
|
.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::<Vec<::syn::Ident>>();
|
.collect::<Vec<::syn::Ident>>();
|
||||||
|
|
||||||
quote! {
|
quote! {
|
||||||
|
@ -192,44 +192,18 @@ pub(crate) fn derive_repository(input: TokenStream) -> TokenStream {
|
|||||||
.into();
|
.into();
|
||||||
}
|
}
|
||||||
// holds the list of all package names, snake case
|
// holds the list of all package names, snake case
|
||||||
let mut all_pkgs =
|
let mut all_pkgs = Vec::<::syn::Ident>::with_capacity(items.fields.len());
|
||||||
Vec::<(String, ::syn::Path)>::with_capacity(items.fields.len());
|
|
||||||
|
|
||||||
for it in items.fields.iter() {
|
for it in items.fields.iter() {
|
||||||
let Some(id) = &it.ident else { continue };
|
let Some(id) = &it.ident else { continue };
|
||||||
let id_str = id.to_string();
|
let id_str = id.to_string();
|
||||||
if id_str.starts_with("_p_") {
|
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();
|
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 pkgs_num: usize = all_pkgs.len();
|
||||||
let (pkg_names, pkg_types): (Vec<String>, 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::<Vec<::syn::Ident>>();
|
|
||||||
|
|
||||||
quote! {
|
quote! {
|
||||||
impl ::bok::Repository for #name {
|
impl ::bok::Repository for #name {
|
||||||
@ -241,14 +215,14 @@ pub(crate) fn derive_repository(input: TokenStream) -> TokenStream {
|
|||||||
}
|
}
|
||||||
fn pkg_list(&self) -> &[&'static str] {
|
fn pkg_list(&self) -> &[&'static str] {
|
||||||
const PKGS : [&'static str; #pkgs_num] = [
|
const PKGS : [&'static str; #pkgs_num] = [
|
||||||
#(#pkg_names),
|
#(stringify!(#all_pkgs)),
|
||||||
*
|
*
|
||||||
];
|
];
|
||||||
&PKGS
|
&PKGS
|
||||||
}
|
}
|
||||||
fn get(&self, pkg_name: &str) -> Option<::std::boxed::Box<dyn ::bok::Pkg>> {
|
fn get(&self, pkg_name: &str) -> Option<::std::boxed::Box<dyn ::bok::Pkg>> {
|
||||||
match pkg_name {
|
match pkg_name {
|
||||||
#(#pkg_names => Some(::std::boxed::Box::new(self.#pkg_ident())),)
|
#(#all_pkgs => Some(::std::boxed::Box::new(self.#all_pkgs())),)
|
||||||
*
|
*
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
@ -505,7 +479,11 @@ pub(crate) fn repo_impl_methods(
|
|||||||
let pkg_name = {
|
let pkg_name = {
|
||||||
let segment = t_id.segments.iter().last().unwrap();
|
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());
|
all_pkgs_types.push(t_id.clone());
|
||||||
if local
|
if local
|
||||||
|
Loading…
Reference in New Issue
Block a user