tiny cleanup

Signed-off-by: Luca Fulchir <luca.fulchir@runesauth.com>
This commit is contained in:
Luca Fulchir 2024-12-11 20:53:27 +01:00
parent 590fdbf25a
commit 87b83371e8
Signed by: luca.fulchir
GPG Key ID: 8F6440603D13A78E
3 changed files with 12 additions and 90 deletions

View File

@ -345,15 +345,3 @@ impl ::syn::parse::Parse for PathList {
Ok(PathList(result)) Ok(PathList(result))
} }
} }
pub(crate) fn path_to_magic_export(p: &::syn::Path) -> ::syn::Path {
let mut tmp = p.clone();
let new_id = {
macro_magic::mm_core::export_tokens_macro_ident(
&tmp.segments.last().unwrap().ident,
)
};
tmp.segments.last_mut().unwrap().ident = new_id;
tmp
}

View File

@ -1073,70 +1073,9 @@ pub(crate) fn package_impl_base_add(
} }
pub(crate) fn derive_package(input: TokenStream) -> TokenStream { pub(crate) fn derive_package(input: TokenStream) -> TokenStream {
let mut input = parse_macro_input!(input as DeriveInput); let input = parse_macro_input!(input as DeriveInput);
let name = input.ident.clone(); let name = input.ident.clone();
let name_builder = quote::format_ident!("{name}Builder");
let elements = match &input.data {
::syn::Data::Struct(s) => match &s.fields {
syn::Fields::Named(n) => n.named.clone(),
_ => panic!("only named supported"),
},
_ => panic!("only struct allowed"),
};
let all_fields = elements.iter().filter_map(|field| {
if let Some(id) = field.ident.clone() {
if id.to_string() != "version"
&& id.to_string() != "_bok_base"
&& id.to_string() != "_bok_repo"
{
if field
.attrs
.iter()
.find(|&a| a.path().is_ident("option"))
.is_none()
{
return None;
}
return Some(&field.ident);
}
}
None
});
let all_fields2 = all_fields.clone();
let all_fields3 = all_fields.clone();
let all_fields_mut = elements.iter().filter_map(|field| {
if let Some(id) = field.ident.clone() {
if id.to_string() != "version"
&& id.to_string() != "_bok_base"
&& id.to_string() != "_bok_repo"
{
return Some(quote::format_ident!("{}_mut", id.to_string()));
}
}
None
});
let all_types = elements.iter().filter_map(|field| {
if let Some(id) = field.ident.clone() {
if id.to_string() != "version"
&& id.to_string() != "_bok_base"
&& id.to_string() != "_bok_repo"
{
return Some(&field.ty);
}
}
None
});
let all_types2 = all_types.clone();
{
let ::syn::Data::Struct(ref mut ds) = input.data else {
panic!("::bok::package expected a struct");
};
let ::syn::Fields::Named(ref mut _old_nf) = ds.fields else {
panic!("::bok::package expected a named field");
};
}
let pkg_struct = quote! { let pkg_struct = quote! {
#input #input
}; };
@ -1227,21 +1166,18 @@ pub(crate) fn derive_package(input: TokenStream) -> TokenStream {
where where
R: ::bok::Repository + 'static + #trait_deps + ::core::default::Default, R: ::bok::Repository + 'static + #trait_deps + ::core::default::Default,
{ {
pub fn as_any(&self) -> &dyn ::std::any::Any {
self
}
pub fn as_any_mut(&mut self) -> &mut dyn ::std::any::Any {
self
}
pub fn as_pkg(&self) -> &dyn ::bok::Pkg { pub fn as_pkg(&self) -> &dyn ::bok::Pkg {
self self
} }
pub fn as_pkg_mut(&mut self) -> &mut dyn ::bok::Pkg { pub fn as_pkg_mut(&mut self) -> &mut dyn ::bok::Pkg {
self self
} }
pub fn builder() -> #name_builder<R> {
#name_builder::<R>::default()
}
#(pub fn #all_fields2(&self) -> &#all_types {
&self.#all_fields2
})*
#(pub fn #all_fields_mut(&mut self) -> &#all_types2 {
&mut self.#all_fields3
})*
} }
}; };

View File

@ -15,13 +15,9 @@
* limitations under the License. * limitations under the License.
*/ */
use ::std::{ use ::std::sync::{Arc, RwLock};
collections::BTreeMap,
sync::{Arc, RwLock},
vec::Vec,
};
use crate::{Path, PkgBuilder, PkgName, RepoName, Repository}; use crate::{PkgBuilder, Repository};
#[derive(Debug, ::thiserror::Error)] #[derive(Debug, ::thiserror::Error)]
pub enum Error { pub enum Error {
@ -32,7 +28,9 @@ pub enum Error {
} }
type ArcLock<T> = Arc<RwLock<T>>; type ArcLock<T> = Arc<RwLock<T>>;
type PkgMap = /*
pub type PkgMap =
BTreeMap<Path<PkgName>, (Arc<dyn Repository>, ArcLock<dyn PkgBuilder>)>; BTreeMap<Path<PkgName>, (Arc<dyn Repository>, ArcLock<dyn PkgBuilder>)>;
*/
pub trait Collection {} pub trait Collection {}